javascript - TypeError:无法读取未定义 vueJS 的属性“_wrapper”
问题描述
我的 VueJS 应用程序有点麻烦。我想要的是在加载时向服务器发送请求,响应我用户的“用户名”并在我的网站上更新它。一切正常,但是当我尝试分配返回值时,我的程序停止加载图像并且标题中的错误出现在控制台中。来自服务器的值是正确的 - 由控制台检查。这是我显示用户名的代码:
<span class="iconsNav" style="margin-left: 4px" >{{this.username}}</span>
这是我的脚本:
<script>
//components
export default {
methods : {
login(){
//function to login
},
async getUserData(){
var token = 'Token '+ VueCookie.get('access_token')
const response = await axios.get('http://localhost:8000/api/account/data',{
headers:{
'Authorization': token
}
})
console.log(response.data.username)
//when i try execute this line error occurs
this.username = response.data.username
}
},
data(){
return {
username : "User"
}
},
mounted: function(){
this.getUserData()
}
}
</script>
解决方案
<span class="iconsNav" style="margin-left: 4px" >{{username}}</span>
要在 vue 中获取数据,您不需要this
.
推荐阅读
- python - 遍历嵌套字典中的特定键
- reactjs - 如何在 React.js 中让 Axios 请求在移动设备上工作
- node.js - 如何在 TypeScript 中使用 mongoose-sequence 项目?
- android - “react-native log-android”错误“adb'logcat -c”失败。adb' logcat -c 运行良好。[Ubuntu]
- c++11 - Lambda 的成员是如何初始化的?
- json - Flutter:自动加载 JSON 数据 StatefulWidget
- javascript - 查看 litElement 中元素的值
- docker - 如何在 docker 的容器 A 中调用命令的容器 B
- android - 找不到符号类 OnCompleteListener
- freebsd - FreeBSD 11 Beaglebone 启用 UART1 和 UART4