【发布时间】:2020-01-09 00:30:12
【问题描述】:
我在我的应用程序/vue 中初始化了一个简单的方法“updateTotal”:
// start app
new Vue({
el: '#app2',
data: {
showModal1: false,
showModal2: false,
total : 0
},
methods: {
updateTotal: function (num) {
this.total = this.total + num
}
}
})
当我从 app2 部分的 HTML 代码中的一个按钮示例调用此方法时,一切正常(文本“total”已更新)。
当我从页面加载时隐藏的 div 部分调用此方法时(它是一个模式,带有 vue.js“过渡”系统),我有这个错误: 属性或方法“updateTotal”未在实例上定义,但在渲染期间被引用。通过初始化该属性,确保该属性是反应性的,无论是在数据选项中,还是对于基于类的组件。
这个模态/转换的代码(它在 app2 div 中)是:
<!-- template for the modal component SERVICES-->
<script type="text/x-template" id="modal2-template">
<transition name="modal2">
<div class="modal-mask">
<div class="modal-wrapper">
<div class="modal-container">
<div class="modal-header">
<slot name="header">
Header
</slot>
</div>
<div class="modal-body">
<!-- LISTE SERVICES -->
<div>
<div>
<div class="control">
<label class="radio">
<input type="radio" name="service1" v-on:click="updateTotal(10)">
Oui
</label>
<label class="radio">
<input type="radio" name="service1" checked v-on:click="updateTotal(-10)">
Non
</label>
</div>
</div>
<div>
<div class="control">
<label class="radio">
<input type="radio" name="service2" v-on:click="updateTotal(20)">
Oui
</label>
<label class="radio">
<input type="radio" name="service2" checked v-on:click="updateTotal(-20)">
Non
</label>
</div>
</div>
</div>
<!-- LISTE SERVICES -->
</div>
<div class="modal-footer">
<slot name="footer">
default footer
<button class="modal-default-button" @click="$emit('close')">
OK
</button>
</slot>
</div>
</div>
</div>
</div>
</transition>
</script>
我该怎么做才能从这个模态/过渡 div 调用这个方法?
谢谢!
MAMP MySQL PHP5
【问题讨论】:
标签: vue.js