出于某种原因,我无法在方法this.active
中访问delete
。什么
这可能是错的?
data () {
return {
ride: { user: {}, location: {}, type: {} },
active: false
}
},
methods: {
delete ()
{
this.active = true;
}
}
因此,如果我点击一个按钮,则会触发删除,但如果我查看vue dev tools
,则保持为false?
答案 0 :(得分:1)
您的问题中的代码在此代码段中运行正常。在您能够重现问题之前,请随意使用此代码段,使其更像您的问题代码。
new Vue({
el: 'body',
components: {
one: {
template: '#one-template',
data() {
return {
ride: {
user: {},
location: {},
type: {}
},
active: false
}
},
methods: {
delete() {
this.active = true;
}
}
}
}
});
<script src="//cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js"></script>
<template id="one-template">
<button @click="delete">Delete</button>
{{active}}
</template>
<one></one>
答案 1 :(得分:-2)
试试这可能对你有所帮助
data () {
return {
ride: { user: {}, location: {}, type: {} },
active: false
}
},
methods: {
delete ()
{
var vm = this ;
vm.active = false;
}
}