使用vuejs组件中的数据绑定与vuex进行选择

时间:2016-06-13 02:08:03

标签: vue.js selectize.js vuex

我做了一个基本上是bootstrap模态的组件。在模态中我想使用selectize(我也尝试过bootstrap select)。问题是,如果select有一些静态值,它可以工作,而如果我用动态数据填充它,它会失败:Uncaught TypeError: Cannot read property 'appendChild' of null

这是html:

<div class="form-group">
    <label for="newContactModalType">Type*</label>
    <select id="newContactModalType" name="type_id">
        <option v-for="type in clientTypes" value="{{ type.id }}">{{ type.name }}</option>
    </select>
</div>

组件:

  export default {
    vuex: {
      getters: {
        clientTypes: state => state.clientTypes.list
      }
    },

    events: {
      'showNewContactModal': () => {
        $('#newContactModal').modal()
      }
    },

    ready() {
      $('#newContactModalType').selectize()
    }
  }

我使用vuex获取clientTypes列表。我意识到这是错误的地方,因为如果我在组件的数据属性中定义clientTypes,它就有效。我不确定我应该在哪里拨打.selectize()。我能想到的最好的就是ready()方法。

提前致谢!

0 个答案:

没有答案
相关问题