gpt4 book ai didi

javascript - vm.handleClick 不是 vue.js 上的函数

转载 作者:行者123 更新时间:2023-12-01 00:50:45 25 4
gpt4 key购买 nike

我正在使用氩模板的切换按钮: argon template docs

我想在切换按钮上放置一个handleChange,但它不起作用,这里是我的代码:

<template>
<div class="option">
<div>Show value
<label class="custom-toggle">
<input type="checkbox" @click="handleClick($event)">
<span class="custom-toggle-slider rounded-circle"></span>
</label>
<div v-if="viewCheck">
<div>Name </div>
<div>Surname</div>
</div>
</div>
</div>
</template>

<script>
export default {
name: 'Options',
data: function() {
return {
viewCheck:false
}
},
handleClick: function(event) {
console.log(event)
this.viewCheck = true
}
}
</script>

事实上,当我单击切换按钮时,我收到以下消息:

TypeError: _vm.handleClick is not a function
at click (eval at ./node_modules/vue-loader/lib/template-compiler/index.js?{"id":"data-v-6f2958af","hasScoped":false,"transformToRequire":{"video":["src","poster"],"source":"src","img":"src","image":"xlink:href"},"buble":{"transforms":{}}}!./node_modules/vue-loader/lib/selector.js?type=template&index=0!./src/views/Option.vue
(app.js:7731), :22:34)
at invokeWithErrorHandling (vue.esm.js?efeb:1863)
at HTMLInputElement.invoker (vue.esm.js?efeb:2188)
at HTMLInputElement.original._wrapper (vue.esm.js?efeb:7559)

最佳答案

您应该将其放在methods 属性中。

试试这个:

export default {
name: 'Options',
data: function() {
return {
viewCheck:false
}
},
methods: {
handleClick: function(event) {
console.log(event)
this.viewCheck = true
}
}
}

关于javascript - vm.handleClick 不是 vue.js 上的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56996419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com