Vue2项目中的一些问题

1. vue创建项目后,在入口文件main.js中使用template模板,项目启动时报错You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

解决方法:

① 使用render代替template进行渲染,但render函数是jsx格式,template为模板引擎格式。

② 在vue.config.js中加入runtimeCompiler:true。

出现问题的原因是由于项目配置时,npm默认进行的是运行时构建即runtime版本且不支持template模板。

 

2.对于ElementUI中进行tag的新增时,造成多个tag共享统一数据的问题。

解决方法:为每个数据源$set动态添加唯一属性,再通过elementUI中的scope.row进行获取。

 

      <template v-slot="scope">
                <el-tag
                  v-for="(item, index) in scope.row.attr_vals"
                  :key="index"
                  closable
                  >{{ item }}</el-tag
                >
                <el-input
                  class="input-new-tag"
                  v-if="scope.row.inputVisible"
                  v-model="scope.row.inputValue"
                  ref="saveTagInput"
                  size="small"
                  @keyup.enter.native="handleInputConfirm"
                  @blur="handleInputConfirm"
                >
                </el-input>
                <el-button
                  v-else
                  class="button-new-tag"
                  size="small"
                  @click="showInput(scope.row)"
                  >+ New Tag</el-button
                >
              </template>
-----------------------------
methods: {
  demo() {
  
    res.data.forEach((item) => {
        item.attr_vals = item.attr_vals ? item.attr_vals.split(" ") : [];
        this.$set(item, "inputVisible", false);
        this.$set(item, "inputValue", "");
      });
}
}

 

posted @ 2022-11-02 09:55  HM-7  阅读(58)  评论(0)    收藏  举报