【问题标题】:Shopware 6: sw-inherit-wrapper property currentValue does not update on selectShopware 6:sw-inherit-wrapper 属性 currentValue 在选择时不更新
【发布时间】:2023-02-06 06:41:14
【问题描述】:

我有一个自定义实体 enterprise,它已分配给 product.extensions.myPlugin.enterpriseId

现在我想在Shopware Vue-Component sw-entity-single-select中选择enterprisesw-inherit-wrapper包装:

<sw-inherit-wrapper
    v-model="product.extensions.myPlugin.enterpriseId"
    :has-parent="false"
    :inherited-value="null">
    <template #content="{currentValue, updateCurrentValue, isInherited}">
        <sw-entity-single-select
            class="enterprise-name"
            :key="isInherited"
            :value="currentValue"
            entity="enterprise"
            :placeholder="$tc('inputEnterprise.placeholder')"
            show-clearable-button
            allow-entity-creation
            :entity-creation-label="$tc('inputEnterprise.labelCreation')"
            @change="updateCurrentValue"></sw-entity-single-select>
    </template>
</sw-inherit-wrapper>

该模板是模态的一部分。

在选择来自给定列表的enterprise&lt;sw-entity-single-select__selection-text&gt;不更新.

跳出进入模板(关闭并重新打开父模态),enterprise 被设置并打印在&lt;sw-entity-single-select__selection-text&gt; 上。
因此,实体扩展已更新,但&lt;sw-entity-single-select__selection-text&gt; 中的属性 currentValue 未更新

例如,我关注sw_product_basic_form_manufacturer_field

问题:为什么财产currentValue未在&lt;sw-entity-single-select&gt; 中选择更新从它的列表中?

【问题讨论】:

    标签: plugins vuejs3 shopware6


    【解决方案1】:

    在不了解更多堆栈的情况下,最好的猜测是 this.product.extensions.myPlugin.enterpriseId 不是反应性的。如果最初设置产品时该属性不存在并且声明如下:

    this.product.extensions.myPlugin = {
        enterpriseId: 'asdf'
    };
    

    enterpriseId 的任何进一步更改都不会是反应性的,并且视图随后在更改时不会更新。

    为了安全起见,您可以将 @change 侦听器添加到 sw-inherit-wrapper 并响应地更新属性:

    onEnterpriseIdChange(enterpriseId) {
        if (!this.product.extensions.myPlugin) {
            this.$set(this.product.extensions, 'myPlugin', {});
        }
        if (!this.product.extensions.myPlugin.enterpriseId) {
            this.$set(this.product.extensions.myPlugin, 'enterpriseId', enterpriseId);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-08
      • 1970-01-01
      • 2015-10-21
      • 2021-08-07
      • 2014-07-11
      • 2020-03-26
      • 1970-01-01
      相关资源
      最近更新 更多