我在Vue.js中有一些自定义组件。在我拥有的一个组件中,有一个选择列表,我希望将其呈现为一个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>
在我将数据添加到Vue实例中的uploads
绑定数组后,视图将使用组件的一个实例进行更新。不幸的是,当我试图在select字段上实例化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>
是否存在在组件完全呈现后触发的事件?
发布于 2016-01-26 00:54:47
您可以在您的组件中尝试两种方法,其中一种方法适用于您的包。在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
}
}
}
发布于 2018-06-25 14:41:33
使用mounted
回调并检查代码中的数据状态。
发布于 2017-10-04 22:46:39
要做到这一点,一个很好的方法是将选择的插件包装在Vue组件中,如详细here中所述。
https://stackoverflow.com/questions/34997541
复制相似问题