Javascript Vue.js在呈现组件后是否会触发事件?
我在Vue.js中有一些自定义组件。在我拥有的其中一个组件中,有一个选择列表,我希望将其渲染为选择框。我使用jQuery函数Javascript Vue.js在呈现组件后是否会触发事件?,javascript,vue.js,Javascript,Vue.js,我在Vue.js中有一些自定义组件。在我拥有的其中一个组件中,有一个选择列表,我希望将其渲染为选择框。我使用jQuery函数$(“select”).selected() 组件完全呈现后是否会触发事件?您可以在组件中尝试两种方法,根据哪一种方法适用于软件包。在Vue对象中: { ready:function(){ // code here executes once the component is rendered // use this in the c
$(“select”).selected()
组件完全呈现后是否会触发事件?您可以在组件中尝试两种方法,根据哪一种方法适用于软件包。在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
}
}
}
正确的方法是: 编辑:Vue 2中的指令语法已更改。*:
Vue.directive("chosen",{
bind: function(el){
$(el).chosen();
}
})
一个很好的方法是将所选插件封装在Vue组件中,如详细所述。使用
挂载的回调并检查代码中的数据状态。这听起来是一个比.missing更优雅的解决方案。选择之前()?谢谢,更正。还要注意,此语法仅适用于Vue 1。在+1之后,它看起来像在vuejs 2中,ready
被替换为updated
,请看这里:我测试了ready
,但它没有work@MajedDH我相信正确的方法应该是挂载
,因为更新涵盖的内容不止这些。我无法使它与就绪
一起工作,但挂载
按预期工作。@asselinpaul,它们是不同的。使用mounted,您无法解决将某些内容绑定到从异步加载的数据动态创建的元素的问题。此处更新。(此帖子似乎没有提供问题的答案。请编辑您的答案并添加更多详细信息,或者仅将其作为问题的评论发布)。
{
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
}
}
}
<select v-chosen name="beats[@{{ index }}][existing_beat]" class="existing-beats">
//insert/require() the following before the creation of your main Vue instance
Vue.directive("chosen",{
bind: function(){
$(this.el).chosen();
}
})
Vue.directive("chosen",{
bind: function(el){
$(el).chosen();
}
})