【发布时间】:2023-03-05 01:44:02
【问题描述】:
我是 vue.js 的新手,在此之前我在我的项目中使用 jquery 或 js,我正在开发一个需要我在按钮单击时动态附加 HTML 元素并同时绑定的项目模型的输入值,类似于:
$(".button").click(function() {
$("#target").append("<input type='hidden' name='data' v-model='inputModel' value='1'/>");
});
但我需要 Vue.js 的方式。
这是我的代码:
data() {
return {
programmeBanner: [],
dropzoneOptions: {
...
...
init: function () {
this.on("success", function(file, response) {
file.previewElement.id = response;
// this is the part that i want to append the html input into
// the .dz-preview is the target that i want to append
$(".dz-preview[id='"+response+"']").append("<input type='hidden' name='"+fileInputName+"[]' v-model='programmeBanner' class='"+fileInputName+"' value='"+response+"'/>");
});
},
...
这是我想要实现的示例,这是在 Jquery 中,我在 Vue.js 中需要它
【问题讨论】:
-
你能告诉我们你尝试了什么吗?
-
@YomS。我的代码已添加
-
使用 vue 实现 dropzone 让您的生活更轻松。 github.com/rowanwins/vue-dropzone
-
感谢 jsfiddle 示例,我已经用一个有效的 vuejs 示例更新了我的答案 :)