为什么element 的score 不能双向绑定(有偿)

活卡进度了 问题1:table 里面循环的input 绑定了v-module 以后不能及时的进行双向绑定,但是最后在点击的时候,能够看到最后的数据是绑定进去的。
问题2 。 通过element ui 上传控件,upSuccess方法在上传成功后,改变了数据中pic相应的位置,为什么没有及时的在tabel 中显示出来? 有偿的!!!!!

<template>
  <div class="commAddWarp">
    <div class="commHeader">
      <p class="title">
        商品添加
      </p>
      <p class="crumbs">
        <a>基础信息</a>>><a>商品参数</a>>><a class="color00b0ec">商品规格</a>>><a>商品详情</a>
      </p>
      <p class="weightTitle">商品规格</p>
    </div>
    <div class="addMain">
      <div class="commSection">
        <div class="guigeCheckBox">
          <el-checkbox-group v-model="weight">
            <span class="title">重量</span>
            <el-checkbox label="10kg"></el-checkbox>
            <el-checkbox label="20kg"></el-checkbox>
            <el-checkbox label="30kg"></el-checkbox>
            <el-checkbox label="50kg"></el-checkbox>
          </el-checkbox-group>
        </div>
        <div class="guigeCheckBox">
          <el-checkbox-group v-model="packaging">
            <span class="title">包装</span>
            <el-checkbox label="实惠盒"></el-checkbox>
            <el-checkbox label="礼盒装"></el-checkbox>
            <el-checkbox label="高档包装"></el-checkbox>
          </el-checkbox-group>
        </div>
        <div class="guigeCheckBox">
          <el-checkbox-group v-model="color">
            <span class="title">颜色</span>
            <el-checkbox label="红色"></el-checkbox>
            <el-checkbox label="白色"></el-checkbox>
            <el-checkbox label="蓝色"></el-checkbox>
            <el-checkbox label="绿色"></el-checkbox>
          </el-checkbox-group>
        </div>
        <p style="font-size: 15px;margin: 20px 0;">
          价格与库存配置</p>
        <el-table :data="tableData1" border
                  style="width: 100%" class="el-table">
          <el-table-column width='150' label="重量">
            <template scope="scope">
              {{scope.row.weight}}
            </template>
          </el-table-column>
          <el-table-column label="包装"
                           v-if="packaging.length>0">
            <template scope="scope">
              <div class="content-rowspan">
                <div
                  v-for="(list,index) in scope.row.packaging">
                  {{list}}
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="颜色" v-if="color.length>0">
            <template scope="scope">
              <div class="content-rowspan">
                <div
                  v-for="(list,index) in scope.row.color"
                  style="border:1px solid #dfe6ec;border-bottom:0;width: 100%;text-align: center;margin-bottom: 20px">
                  <p v-for="(item,index) in list"
                     style="border-bottom: 1px solid #dfe6ec">
                    {{item}}
                  </p>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="价格">
            <template scope="scope">
              <div class="content-rowspan">
                <div
                  v-for="(sList,sIndex) in scope.row.price"
                  style="padding: 15px;">
                  <div v-for="(item,index) in sList"
                       style="margin-bottom: 5px">
                    <!--<input type="text" >-->
                    <el-input v-model="sList[index]"
                              placeholder="请输入库存"
                              style="height: 28px"></el-input>
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="库存">
            <template scope="scope">
              <div class="content-rowspan">
                <div
                  v-for="(sList,sIndex) in scope.row.inventory"
                  style="padding: 15px;">
                  <div v-for="(item,index) in sList"
                       style="margin-bottom: 5px">
                    <el-input v-model="sList[index]"
                              placeholder="请输入库存"></el-input>
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column width='200' label="操作">
            <template scope="scope">
              <div v-for="(sList,sIndex) in scope.row.pic" style="padding: 15px">
                <div v-for="(item,index) in sList" style="margin-bottom: 5px">
                  <el-upload
                    class="upload-demo"
                    action="http://gonghaoht1.sinmore.vip/api/ossStoreImg"
                    name="pic"
                    :data="{model:1}"
                    :show-file-list="false"
                    :on-success="upSuccess"
                  >
                    <img v-if="sList[index]" :src="sList[index]" class="avatar">
                    <el-button
                      @click.native.prevent="upload(sIndex,index,scope)" type="primary"
                    >上传<i class="el-icon-upload el-icon--right"></i></el-button>
                  </el-upload>
                  <!--<span v-model="">{{]}}</span>-->

                </div>
              </div>

            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="btnWarp">
      <a class="blackBtn">上一步</a>
      <a class="blackBtn" @click="lookkk">下一步</a>
    </div>
  </div>
</template>
<script type="text/ecmascript-6">
  export default{
    name: 'commSpecification',
    data() {
      return {
        weight: [],
        packaging: [],
        color: [],
        arrs: [],
        price: [],
        inventory: [],
        pic: [],
        nowList :{

        }
      }
    },
    computed: {
      tableData1(){
        let tabArrs = [];
        let _this = this;
        for (let i = 0; i < this.weight.length; i++) {
          let obj = new Object;
          obj.weight = this.weight[i];
          obj.packaging = [];
          obj.color = [];
          obj.price = [];
          obj.inventory = [];
          obj.pic = [];
          for (let w = 0; w < this.packaging.length; w++) {
            obj.packaging.push(this.packaging[w]);
            let colors = [];
            let price = [];
            let inventory = [];
            let pic = [];
            for (let q = 0; q < this.color.length; q++) {
              colors.push(this.color[q]);
              price.push(' ');
              inventory.push(' ');
              pic.push(' ');
            }
            obj.color.push(colors);
            obj.price.push(price);
            obj.inventory.push(inventory);
            obj.pic.push(pic)
          }
          _this.price = obj.price;
          _this.inventory = obj.inventory;
          _this.pic = obj.pic;
          tabArrs.push(obj)
        }
        return tabArrs;
      }
    },
    methods: {
      upload: function (ee,qqq,kkk) {
        this.nowList.indeex = ee;
        this.nowList.sindeex = qqq;
        this.nowList.scope = kkk;
        console.log(this.nowList)
      },
      upSuccess(re){
        this.tableData1[this.nowList.scope.$index].pic[this.nowList.indeex][this.nowList.sindeex] = re.data.url;
      },
      lookkk(){
        console.log(this.tableData1)
      }
    }
  }
</script>
<style>
  @import "../../../../static/css/commdetail/commAdd/commAdd.css";
</style>
阅读 3.7k
3 个回答
 upSuccess(re){
 this.tableData1[this.nowList.scope].pic[this.nowList.indeex].splice([this.nowList.sindeex], 1, re.data.url);
 }       

代码太长了,看不清。
这属于是组件之间传递信息了,出现不更新,就说明某个组件内部没有正确使用vue的处理程序,或者数据传输断掉了。你可以拿到某次new vue()的data在更改前后进行观察。
使用全局数据中心vuex,或者,传到父级的父级(模拟原生冒泡)

如果你嫌麻烦试试手动更新。vue官网更新数据描述
或者可能你是修改的数组,vue对数组的直接修改不会更新视图,需要用数组的指定方法才行。vue数组数据更新

这么想吧,computed 负责把数据按照你喜欢的方式处理然后展现,仅此而已,不能在其它地方对 computed 的结果修改。

你的 upSuccess 里对 tableData1 的修改很明显是无效的。把 tableData1: [] 放到 data 里,原有的 computed 代码重构为一个 method 用来修改 tableData1,然后在 created 钩子里体用该 method 初始化。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题