我在 Vue.js 中有一些自定义组件。在我拥有的一个组件中有一个选择列表,我想将其呈现为Chosen http://harvesthq.github.io/chosen/选择框。我将其与 jQuery 函数一起使用$("select").chosen()
.
<template v-for="upload in uploads">
<new-upload-container :index="$index" :upload="upload" v-if="isNewUpload"></new-upload-container>
<existing-upload-container :index="$index" :upload="upload" v-if="isExistingUpload"></existing-upload-container>
</template>
当我将数据添加到uploads
Vue 实例中的绑定数组,视图会使用组件的实例进行更新。不幸的是当我尝试实例化时Chosen
在选择字段上,它不起作用。
我不确定将项目添加到后是否需要很短的时间uploads
DOM 实际更新的绑定数组。
<template id="existing-upload-container">
<select name="beats[@{{ index }}][existing_beat]" class="existing-beats">
<option selected="selected" value="">-- Select a linked beat --</option>
@foreach ($beats as $beat)
<option value="{{$beat->id}}">{{$beat->name}}</option>
@endforeach
</select>
</template>
组件完全渲染后是否有触发事件?
您可以在组件中尝试两项操作,具体取决于哪一项适用于您的包。在 Vue 对象中:
{
ready:function(){
// code here executes once the component is rendered
// use this in the child component
},
watch: {
uploads:function(){
//code here executes whenever the uploads array changes
//and runs AFTER the dom is updated, could use this in
//the parent component
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)