KoG*_*oro 8 vue.js vue-component vuejs2
请帮忙!我在子模板中有“未定义”道具。
主要js:
// some code before
window.Vue = require('vue');
import EventBus from '../components/event-bus';
// some code after
Vue.component('calendar-select', require('../components/admin/calendar_select.vue'));
const app = new Vue({
el: '#app',
data: function() {
return {
isActiveCalendar: true
}
},
methods: {
toggleCalendar() {
this.isActiveCalendar = !this.isActiveCalendar;
}
},
mounted() {
EventBus.$on('toggleCalendar', this.toggleCalendar);
}
});
Run Code Online (Sandbox Code Playgroud)
在此之后,我创建了这样的模板:
<template>
<div class="custom-select" v-bind:class="{ active: isActiveCalendar}" >
<div class="box flex" v-on:click="toggleCalendar" >
<span>Calendar</span>
<img src="/assets/img/admin/arrow-down.png" alt="#">
</div>
</div>
</div>
</template>
<script>
import EventBus from '../event-bus';
export default
{
// ------- start
props: ['isActiveCalendar'],
data: function() {
return {
}
},
methods: {
toggleCalendar: function(event) {
console.log(this.isActiveCalendar)
EventBus.$emit('toggleCalendar');
}
}
// ------- end
}
</script>
Run Code Online (Sandbox Code Playgroud)
当我在this.isActiveCalendar上执行console.log时,该变量未定义,并且在 Chrome 的 Vue 插件中也是一样。
请告诉我,我在做什么错误!
谢谢!
Jus*_*hur 15
如传递道具的文档中所述。
HTML attributes are case-insensitive, so when using non-string templates, camelCased prop names need to use their kebab-case (hyphen-delimited) equivalents:
在这个例子中,你需要使用
<calendar-select v-bind:is-active-calendar="isActiveCalendar"></calendar-sele??ct>
Run Code Online (Sandbox Code Playgroud)
以便它将变量的值传递给道具。
| 归档时间: |
|
| 查看次数: |
18828 次 |
| 最近记录: |