【Uni-App】出现Cannot read property ’apply’ of undefined错误
错误日志如下:14:47:00.951 [system] [object] {"message":"Cannot read property 'apply' of undefined","stack":"TypeError: Cannot read property 'apply' of...}当我点击一个按钮的时候,控制台弹出以上日志,看他的message:Cannot read propert
·
错误日志如下:
14:47:00.951 [system] [object] {"message":"Cannot read property 'apply' of undefined","stack":"TypeError: Cannot read property 'apply' of...}
当我点击一个按钮的时候,控制台弹出以上日志,看他的message:Cannot read property ‘apply’ of undefined(无法读取未定义的属性“apply”)
<template>
<button @click="test">调试</button>
</template>
<script>
export default {
methods: {},
test: function() {
console.log('sadfas');
}
};
</script>
有基础的可能一眼就会看出
test: function() {
console.log('sadfas');
}
这个方法应该写在methods: {},
里,而不是放在methods: {},
外。
修改后:
<template>
<button @click="test">调试</button>
</template>
<script>
export default {
methods: {
test: function() {
console.log('sadfas');
}
}
};
</script>
点击按钮后就会正常打印出结果:
14:53:50.098 sadfas at pages/index/index.vue:9
更多推荐
所有评论(0)