【发布时间】:2019-04-02 03:06:20
【问题描述】:
当 Vue.js 中名为 q 的组件属性被修改时,我正在尝试运行名为 query() 的方法。
这会失败,因为 this.query() 未定义。 This 指的是我的组件的实例,但不知何故不包含方法。
这是我试图查看组件属性q 并运行query() 函数的相关代码部分:
methods: {
async query() {
const url = `https://example.com`;
const results = await axios({
url,
method: 'GET',
});
this.results = results.items;
},
debouncedQuery: _.debounce(() => { this.query(); }, 300),
},
watch: {
q() {
this.debouncedQuery();
},
},
错误:
TypeError: _this2.query 不是函数
如果我编写如下debounce() 调用,TypeError: expected a function 错误会更早出现,在页面加载时。
debouncedQuery: _.debounce(this.query, 300),
【问题讨论】:
标签: javascript vue.js lodash