1.4.0
win10
2.4.2
https://jsfiddle.net/uxnxpshq/
点击table展开 setTimeOut模拟异步获取数据
但是数据在更新后并不会立即更新到dom上
必须再次点击展开才会更新
可以改之为响应式更新吗?
table展开项异步更新dom
table展开项在下一次才会更新dom
Translation of this issue:
1.4.0
Win10
2.4.2
https://jsfiddle.net/uxnxpshq/
Click table to expand the setTimeOut simulation to obtain the data asynchronously
However, the data is updated and will not be updated immediately to the DOM
You must click on "expand" again to update
Can I change it to a response update?
The table expansion entry asynchronously updates the DOM
The table expansion entry will update the DOM next time
这个不是 Element UI 的问题
你的数据里的 test 属性不是响应式的,所以你改了之后没有动态更新,具体可参考 Vue 官方文档
var Main = {
data() {
return {
tableData5: [{
id: '12987122',
name: '好滋好味鸡蛋仔',
category: '江浙小吃、小吃零食',
desc: '荷兰优质淡奶,奶香浓而不腻',
address: '上海市普陀区真北路',
shop: '王小虎夫妻店',
shopId: '10333',
// 预先定义 test 属性
test: ''
}]
}
},
methods:{
expendFn:function(row){
setTimeout(function(){
row.test = "testtest"
},500)
}
}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
var Main = {
data() {
return {
tableData5: [{
id: '12987122',
name: '好滋好味鸡蛋仔',
category: '江浙小吃、小吃零食',
desc: '荷兰优质淡奶,奶香浓而不腻',
address: '上海市普陀区真北路',
shop: '王小虎夫妻店',
shopId: '10333'
}]
}
},
methods:{
expendFn:function(row){
// 此处可使用箭头函数改善
var $vm = this;
setTimeout(function(){
// row.test = "testtest"
$vm.$set(row, 'test', 'testtest')
}, 500)
}
}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
@bltbbb 请参照楼上。
我补充一下修改后的 demo:
谢谢二位
我之前考虑到了响应式属性的原因,于是直接在methods里修改了tabledata5的数据,然后在展开层自己v-for循环一遍,发现还是没有变化,所以才得出这个结论,@BaffinLee 的回答让我更深一步的认识到了响应式属性的意思。
用了$set添加了异步返回的数据后 expand 不晓得为啥自己关掉了。。。
版本已经是 2.4.1 了
@Palenew 我也遇到这个问题,版本都是2.4.6了,用了$set添加数据,expand还会自动关掉,需要连续点击才好,请问你是怎么解决的?
@Palenew 我也遇到这个问题,版本都是2.4.6了,用了$set添加数据,expand还会自动关掉,需要连续点击才好,请问你是怎么解决的?
您好,我在项目里也遇到了相同的问题,"element-ui": "2.4.6",请问有好的解决方案吗?
用了$set添加了异步返回的数据后 expand 不晓得为啥自己关掉了。。。
版本已经是 2.4.1 了
这个问题最后是如何解决的,期待您的回答,谢谢
Most helpful comment
用了$set添加了异步返回的数据后 expand 不晓得为啥自己关掉了。。。
版本已经是 2.4.1 了