Vue.js Vuejs取消发布监视的属性,并使用VueX调用存储
在一个基本组件中,我正在尝试对监视的属性进行去盎司处理并使用VueX存储:Vue.js Vuejs取消发布监视的属性,并使用VueX调用存储,vue.js,vuejs2,vuex,Vue.js,Vuejs2,Vuex,在一个基本组件中,我正在尝试对监视的属性进行去盎司处理并使用VueX存储: import _ from 'lodash'; import { mapGetters } from 'vuex'; export default { name: "search-filters", data() { return { test: 'test' } }, watch: { linkName: 'check
import _ from 'lodash';
import { mapGetters } from 'vuex';
export default {
name: "search-filters",
data() {
return {
test: 'test'
}
},
watch: {
linkName: 'checkLinkName',
},
computed: {
...mapGetters({
routeLinkName: 'linkName',
})
},
methods: {
checkLinkName: _.debounce((newVal, oldVal) => {
console.log(newVal, oldVal, this.test);
// this.$store.commit('something') is not working too
}).bind(this)
}
}
我在checkLinkName
中获得旧值和新值,但无法访问测试属性(或$store,或映射的getter)
我试过这样的方法:linkName:uu.debounce(this.checkLinkName,180)
但它告诉我们checkLinkName不是一个函数
我尝试创建自己的去盎司函数:
const debounce = function(fn, time, context) {
let timeout;
return function() {
const functionCall = () => fn.apply(context, arguments);
clearTimeout(timeout);
timeout = setTimeout(functionCall, time);
}
};
但是仍然没有定义。您遇到了此的绑定上下文的问题,请尝试在谴责调用中使用箭头符号
data () {
return {
debouncer: null
}
},
created () {
this.debouncer = _.debounce((newVal, oldVal) => {
console.log(newVal, oldVal, this.test)
this.$store.commit('something')
}, 250)
this.debouncer.bind(this)
},
watch: {
linkName: this.debouncer
},
我已经尝试过了,但从未使用此方法调用
控制台.log
。直接使用discount作为观察者处理程序如何?是的,我也尝试过此方法,并且使用此方法未定义。测试。我想您需要使用function关键字is this case而不是箭头符号。我仍然使用function关键字未定义