Vue.js && Shopware 6 是否有可能通过@input传递目标元素?

标签 vue.js shopware6

我正在尝试构建一个具有多个文本字段的自定义 cms 元素。

因此我修改了 cms-text 元素的代码并对其进行了自定义。

每当我想更改一个文本字段的值时,所有其他值也会发生变化。

是否有可能通过@input/@blur传递目标?

所有元素都很相似,如下所示:

<sw-text-editor
                            v-model="element.config.information.value"
                            :allow-inline-data-mapping="true"
                            sanitize-input
                            @input="onInput"
                            @blur="onBlur"
                        />

vue:

onBlur(content) {
            this.emitChanges(content);
        },

        onInput(content) {
            this.emitChanges(content);
        },

        emitChanges(content) {
            if (content !== this.element.config.productName.value && this.element.config.productName.source !== 'mapped') {
                this.element.config.productName.value = content;
                this.$emit('element-update', this.element);
                console.log(this.element)
            }

            if(content !== this.element.config.subtitle.value && this.element.config.subtitle.source !== 'mapped'){
                this.element.config.subtitle.value = content;
                this.$emit('element-update', this.element);
                return;
            }

            if(content !== this.element.config.information.value && this.element.config.information.source !== 'mapped'){
                this.element.config.information.value = content;
                this.$emit('element-update', this.element);
            }
        },

最佳答案

您可以在内联事件处理程序中使用 $event 传递原始事件,并以这种方式传递更多变量,例如属性名称。

<sw-text-editor
    v-model="element.config.information.value"
    :allow-inline-data-mapping="true"
    sanitize-input
    @input="onChange('information', $event)"
    @blur="onChange('information', $event)"
/>
<sw-text-editor
    v-model="element.config.productName.value"
    :allow-inline-data-mapping="true"
    sanitize-input
    @input="onChange('productName', $event)"
    @blur="onChange('productName', $event)"
/>
onChange(propertyName, content) {
    if (content !== this.element.config[propertyName].value && this.element.config[propertyName].source !== 'mapped') {
        this.element.config[propertyName].value = content;
        this.$emit('element-update', this.element);
    }
}

关于Vue.js && Shopware 6 是否有可能通过@input传递目标元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74196579/

相关文章:

javascript - 如何为每个元素添加唯一的事件监听器

shopware6 - 商店软件 6 : What is the usage or benefit of the custom/static-plugins folder?

shopware6 - Shopware 6 中 `categories` 和 `mainCategories` 之间的区别?

Shopware6:缺少插件配置

javascript - 如何在用 php、apache 服务器编写的网站子程序上激活 vue-router 的历史记录模式?

javascript - 使用数组和 v-for (Vue.js) 传递点击操作

javascript - 如何在Vue js中做一个无限滚动,动态渲染一个列表(只可见)

vue.js - 如何对对象数组进行 v-model

request - 如何在shopware 6中访问订阅者中的请求数据

shopware - Shopware 6 订单付款方式错误