更新 vuex 状态的 vue 生命周期方法
vue life cycle method for updated vuex state
我正在使用 Vue 和 Vuex。在我的组件中,我有以下代码:
computed: {
...mapState({
address: state => state.wallet.address
})
},
它在 UI 中运行良好,但我想做的是在地址更改其值后立即调用方法。知道如何触发它吗?
watcher 可能对您的情况有所帮助。您可以创建一个观察者来检测计算地址的变化 属性。一旦值改变,观察者将被执行。请参阅附件中的示例。
var vm = new Vue({
el: '#demo',
computed: {
...mapState({
address: state => state.wallet.address
})
},
watch: {
address: function (newAddress, oldAddress) {
// this watcher will be called once address changed
// you can have access to previous and new values.
},
}
})
Mounted 是生命周期中最常用的钩子。 mounted() 被称为
在 DOM 安装后,您可以访问反应组件,
模板和 DOM 元素并对其进行操作。
在服务器端渲染中 created() 被用于 mounted() 因为
其中不存在 mounted()。
---> 安装()<---
我正在使用 Vue 和 Vuex。在我的组件中,我有以下代码:
computed: {
...mapState({
address: state => state.wallet.address
})
},
它在 UI 中运行良好,但我想做的是在地址更改其值后立即调用方法。知道如何触发它吗?
watcher 可能对您的情况有所帮助。您可以创建一个观察者来检测计算地址的变化 属性。一旦值改变,观察者将被执行。请参阅附件中的示例。
var vm = new Vue({
el: '#demo',
computed: {
...mapState({
address: state => state.wallet.address
})
},
watch: {
address: function (newAddress, oldAddress) {
// this watcher will be called once address changed
// you can have access to previous and new values.
},
}
})
Mounted 是生命周期中最常用的钩子。 mounted() 被称为 在 DOM 安装后,您可以访问反应组件, 模板和 DOM 元素并对其进行操作。 在服务器端渲染中 created() 被用于 mounted() 因为 其中不存在 mounted()。
---> 安装()<---