vue中Select下拉框用v-model绑定了一个值,用v-for遍历出来多个,改变一个下拉框的选项,其他的都会改变将途中这个遍历出来多个,改变其中一个的值,其他都会变,我应该怎样解决??不让他们联动

解决方案 »

  1.   

    不要绑定同一个v-model
      

  2.   

    @summer_雪
      就是  现在循环出来的数据下拉框选择其中一个 其他的数据的下拉框也跟着改变成同样的值, 因为他们的v-model绑定是同一条数据(循环出来的数据v-mdel不能改变)。现在就是想让它单独来选 其他的不受影响
      

  3.   

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
    </head>
    <body>
        <div id="app">
            <select v-model="selectedA">
                <option v-for="option in options" v-bind:value="option.value">{{ option.text }}
                </option>
            </select>
            <span>SelectedA: {{ selectedA }}</span>
            <hr />
            <select v-model="selectedB">
                <option v-for="option in options" v-bind:value="option.value">{{ option.text }}
                </option>
            </select>
            <span>SelectedB: {{ selectedB }}</span>
            <hr />
            <select v-model="selectedC">
                <option v-for="option in options" v-bind:value="option.value">{{ option.text }}
                </option>
            </select>
            <span>SelectedC: {{ selectedC }}</span>
            <hr />
        </div>
    </body>
    </html>
    <script src="../../Scripts/VUE/vue.js"></script>
    <script>
        new Vue({
            el: '#app',
            data: {
                selectedA: 'A',
                selectedB: 'B',
                selectedC: 'C',
                options: [
                  { text: 'One', value: 'A' },
                  { text: 'Two', value: 'B' },
                  { text: 'Three', value: 'C' }
                ]
            }
        })
    </script>
      

  4.   

    我的是循环出来的数据 v-model只能绑定同一数据。
      

  5.   

    你现在是有多个select下拉选择框吗?每个都是循环的?
      

  6.   

    1.修改源数据,添加一个selectVal 属性,并把下拉菜单的第一个赋值到这里
    this.goodsList.forEach((item,index)=>{
                  item.checkd = false
                  item.index = index
                  item.selectVal = item.attr_name[0]
                })2.在视图层使用刚手动添加的属性,获取属性值
    <span>{{item.selectVal}}</span>3.在下来选择框中更改源数据中新增加的selectVal的属性值
    selectTypeHandle(item,e,index) {
          item.selectVal = e.currentTarget.dataset.value;
        },