我试图运行一个名为query()
的方法,但Vue中的组件属性名为q
.js被修改了.
这失败了,因为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();
},
},
错误:
Type错误: _this2.query is not a function
If I write the debounce()
call as below, the Type错误: expected a function
error appears even earlier, at the page load.
debouncedQuery: _.debounce(this.query, 300),