Vue js 和克隆组件
Vue js and cloned components
我有一个表单,其中包含由 Vue js 管理的 v-select 列表,我应用程序中的所有 select 都由该模块管理,其他输入字段是示例 html 字段。
当我使用 jquery 克隆表单时,我失去了在我的 select 中单击的所有操作。
任何人都知道如何添加 jquery v-select 克隆的 html 作为 Vue 组件?
vue select 是这样管理的:
init: function () {
const node = $('.custom-vue-select');
if (node) {
node.each(function (index) {
let id = index;
App.components['customVueSelect_' + id] = new Vue({
'el': this,
'mixins': [App.customVueSelect.mixins]
});
App.lazy(this, function () {
App.components['customVueSelect_' + id] && App.components['customVueSelect_' + id].reset();
});
});
}
}
jquery 有一个解决方案:替换 Vue js 生成的 DOM 并创建另一个这样的:
let vuSelect = $('.v-select');
if (vuSelect) {
let id = vuSelect.attr('id'),
template = `
<v-select class="form-control custom-combobox"
id="${id}"
name="${id}">
</v-select>
`;
vuSelect.replaceWith(template);
new Vue({ el: '#components-select' });
}
我有一个表单,其中包含由 Vue js 管理的 v-select 列表,我应用程序中的所有 select 都由该模块管理,其他输入字段是示例 html 字段。 当我使用 jquery 克隆表单时,我失去了在我的 select 中单击的所有操作。 任何人都知道如何添加 jquery v-select 克隆的 html 作为 Vue 组件? vue select 是这样管理的:
init: function () {
const node = $('.custom-vue-select');
if (node) {
node.each(function (index) {
let id = index;
App.components['customVueSelect_' + id] = new Vue({
'el': this,
'mixins': [App.customVueSelect.mixins]
});
App.lazy(this, function () {
App.components['customVueSelect_' + id] && App.components['customVueSelect_' + id].reset();
});
});
}
}
jquery 有一个解决方案:替换 Vue js 生成的 DOM 并创建另一个这样的:
let vuSelect = $('.v-select');
if (vuSelect) {
let id = vuSelect.attr('id'),
template = `
<v-select class="form-control custom-combobox"
id="${id}"
name="${id}">
</v-select>
`;
vuSelect.replaceWith(template);
new Vue({ el: '#components-select' });
}