首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Vue.js事件会在组件呈现后触发吗?

Vue.js事件会在组件呈现后触发吗?
EN

Stack Overflow用户
提问于 2016-01-26 00:33:03
回答 3查看 33.1K关注 0票数 23

我在Vue.js中有一些自定义组件。在我拥有的一个组件中,有一个选择列表,我希望将其呈现为一个Chosen选择框。我将其与jQuery函数$("select").chosen()一起使用。

代码语言:javascript
复制
<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实际更新的项后,是否需要很短的时间。

代码语言:javascript
复制
<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>

是否存在在组件完全呈现后触发的事件?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-01-26 00:54:47

您可以在您的组件中尝试两种方法,其中一种方法适用于您的包。在Vue对象中:

代码语言:javascript
复制
{
    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
        }
    }
}
票数 13
EN

Stack Overflow用户

发布于 2018-06-25 14:41:33

使用mounted回调并检查代码中的数据状态。

票数 1
EN

Stack Overflow用户

发布于 2017-10-04 22:46:39

要做到这一点,一个很好的方法是将选择的插件包装在Vue组件中,如详细here中所述。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34997541

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档