我在 Vue.js(2) 中有一个自定义组件:
Vue.component("modal-panel", {
props: {
id: {
required: true
},
title: {} ,
size: {
validator: function(value) {
return !value || value=="lg" || value=="sm";
}
},
confirmLabel: {
"default": "Yes",
},
closeLabel: {
"default": "No"
},
confirm: {
type: Function
}
},
//...
template: `
//...
<button type="button" class="btn btn-primary confirm" data-dismiss="modal" v-on:click="$emit('confirm')" v-if="confirm">{{confirmLabel}}</button>
//...
`
}
Run Code Online (Sandbox Code Playgroud)
这是使用组件的代码
<modal-panel title="New User" id="userModal" @confirm="doSomething">...</modal-panel>
Run Code Online (Sandbox Code Playgroud)
从组件代码可以看出,props中已经插入了confirm,并且模板中的按钮代码上有根据是否附加confirm监听器进行条件渲染。但是,按钮未呈现。我检查了组件dom和属性,但没有这样的信息。
是否可以根据 vue.js 中的组件是否附加特定侦听器来进行条件渲染?
谢谢。