首页 > 解决方案 > 动态数据分配不适用于 Vue js

问题描述

所以我有这段代码,它循环遍历this.product.taxons每个元素,它查看对象数组this.taxons以找到taxon具有相同值的 。

this.product.taxons.forEach((taxon) => {
    // taxon = 'bed_sheet'
    const data = this.taxons.find((x) => x.value === exclusion);
    // data = {
    //   value: 'bed_sheet',
    //   model: 'bedSheet'
    // }
    this.currentProduct.`${data.model}` = true; // this does not work.
  });

但我的问题this.currentProduct.'${data.model}' = true;是翻译成this.currentProduct.bedSheet = true;

并以任何其他方式返回错误SyntaxError: Unexpected token 来实现这一点?

标签: vue.jsvuejs2

解决方案


推荐阅读