data是这样的
data () {
return {
username: '',
pw: '',
pw2: ''
}
}
然后methods的一个方法里面这样解构赋值不对吧 this指向当前组件 直接赋值不行吧 我打印username显示是空
const {username, pw, pw2} = this
data是这样的
data () {
return {
username: '',
pw: '',
pw2: ''
}
}
然后methods的一个方法里面这样解构赋值不对吧 this指向当前组件 直接赋值不行吧 我打印username显示是空
const {username, pw, pw2} = this
this.username = '张三'
const {username, pw, pw2} = this
consloe.log(username) // 张三
其实已经解构出来了,显示为空是因为你初始值就是空的,你吧username 设置个值看看
9 回答1.7k 阅读✓ 已解决
6 回答1.5k 阅读
3 回答1.4k 阅读✓ 已解决
4 回答1.2k 阅读✓ 已解决
2 回答1.2k 阅读✓ 已解决
3 回答1k 阅读
3 回答1.3k 阅读✓ 已解决
这种解构在
vue
中只能用来获取 不能用来操作 因为是值的赋值你只是用作打印的话没问题 可能
username
是异步赋值的