如何在更新状态时和 DOM 满载后调用函数
How to call function when update state and after DOM full loaded
我想在更新状态和 DOM 完全加载后,我将使用 js 来更新 CSS。所以现在,我在方法中使用 document ready function
。 Vuex 有写法吗?我怎样才能将它们写入挂载?
computed: {
...mapGetters([
'wsInfo'
])
},
mounted () {
??????
},
method: {
moveWs (from, to) {
//update state
this.wsInfo.workspaces.splice(to, 0, this.wsInfo.workspaces.splice(from, 1)[0])
$(document).ready(function () {
// code run after update state and dom loaded
})
}
}
您需要使用 nextTick 函数。
您也可以在方法 vuejs 对象中使用它。
您可以在此处阅读更多相关信息:
https://vuejs.org/v2/api/#vm-nextTick
new Vue({
// ...
methods: {
// ...
example: function () {
// modify data
this.message = 'changed'
// DOM is not updated yet
this.$nextTick(function () {
// DOM is now updated
// `this` is bound to the current instance
this.doSomethingElse()
})
}
}
})
我想在更新状态和 DOM 完全加载后,我将使用 js 来更新 CSS。所以现在,我在方法中使用 document ready function
。 Vuex 有写法吗?我怎样才能将它们写入挂载?
computed: {
...mapGetters([
'wsInfo'
])
},
mounted () {
??????
},
method: {
moveWs (from, to) {
//update state
this.wsInfo.workspaces.splice(to, 0, this.wsInfo.workspaces.splice(from, 1)[0])
$(document).ready(function () {
// code run after update state and dom loaded
})
}
}
您需要使用 nextTick 函数。 您也可以在方法 vuejs 对象中使用它。
您可以在此处阅读更多相关信息:
https://vuejs.org/v2/api/#vm-nextTick
new Vue({
// ...
methods: {
// ...
example: function () {
// modify data
this.message = 'changed'
// DOM is not updated yet
this.$nextTick(function () {
// DOM is now updated
// `this` is bound to the current instance
this.doSomethingElse()
})
}
}
})