Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select选择器,label值不变 #71

Closed
tdida opened this issue Sep 14, 2016 · 12 comments
Closed

select选择器,label值不变 #71

tdida opened this issue Sep 14, 2016 · 12 comments

Comments

@tdida
Copy link

tdida commented Sep 14, 2016

maps=[{
  "name": "福建",
  "city": [{
    "name": "福州"
  },{
    "name": "厦门"
  }]
},{
  "name": "广东",
  "city": [{
    "name": "广州"
  },{
    "name": "深圳"
  }]
}]

computed: {
    city: function() {
      for (let province of this.maps) {
        if (this.onProvince == province.name) {
          return province.city
        }
      }
    }
  },

<el-select v-model="onProvince">
     <el-option
        v-for="(item, index) in maps"
        :label="item.name"
        :key="index"
        :value="item.name">
        </el-option>
     </el-select>
 <el-select v-model="onCity">
     <el-option
         v-for="(item, index) in city"
        :label="item.name"
        :key="index"
        :value="item.name">
    </el-option>
</el-select>

这是一个地区联动选择器,省级选择器选择后,市级的el-select选择器会出现第一个el-option的label值不变,value有变的情况

@Leopoldthecoder
Copy link
Contributor

由于设置了 :key="index",当 onProvince 变化后 index 的值没有变化,所以 Vue 2.0 不会重新渲染。建议改为 :key="item.name",同时在 onProvince 变化后处理一下 onCity 的值。

@tdida
Copy link
Author

tdida commented Sep 14, 2016

@Leopoldthecoder 多谢,解决了

@tdida tdida closed this as completed Sep 14, 2016
@QingWei-Li
Copy link
Contributor

@Leopoldthecoder 写文档里?

@csvwolf
Copy link
Contributor

csvwolf commented Sep 14, 2016

@QingWei-Li Vue本身的不需要写文档吧?

@Leopoldthecoder
Copy link
Contributor

其实文档里提了一句,可能不太明显,我想想怎么改一下

@QingWei-Li
Copy link
Contributor

@csvwolf 不写的话出问题就赖 Element 🌚

@csvwolf
Copy link
Contributor

csvwolf commented Sep 14, 2016

@QingWei-Li -0-(逃2333

@perfectyang
Copy link

Leopoldthecoder ,按照你的方法,我同时在 onProvince 变化后处理一下 onCity 的值,发现出现第一个el-option的label值不变,还是不变,
"element-ui": "^1.0.0-rc.4",
"vue": "2.0.0-rc.6",

computed: {
city () {
console.log('cicici', this.onCity)
for (const province of this.maps) {
if (this.onProvince == province.name) {
this.onCity = ''
return province.city
}
}
}

@perfectyang
Copy link

代码如下:







@Leopoldthecoder
Copy link
Contributor

@perfectyang 我按你说的写了个 Demo:https://jsfiddle.net/gL6mf2te/ ,看起来是正常的。你说的 label 值不变是指什么?

@maverickchangithub
Copy link

抱歉, 我也有同样的问题。似乎在mac os 12.4里才会发生。
chrome 58 , element-ui网站上都ok,上面jsfiddle的例子也ok,就是自己使用不行,select后label显示不变。
同样的代码在el captian上就似乎没有问题。
我使用laravel。
多谢!

hazel54 pushed a commit to hazel54/element that referenced this issue Aug 29, 2018
@tomastong
Copy link

el-select组件的onchange方法,执行this.$forceUpdate(); 重新渲染实例就好了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants