el-select下拉框动态获取及默认选中当前元素

el-select下拉框动态获取及默认选中当前元素_第1张图片

<el-col :span="2">
            <el-select placeholder="本体库选择" 
            	v-model="ontologyName" 
            	style="width: 130px" 					
            	@change="changeOnto(ontologyName)">
                
                <el-option 
                	v-for="(item) in ontoList" 
                	:key="item.onto_name" 
                	:value="item.onto_name" 	
                	:label="item.onto_name">		
            	el-option>
            el-select>
el-col>
data () {
	return {
	ontoList: [], //本体名称列表
	ontologyName: this.$route.params.ontology ? this.$route.params.ontology : this.$store.state.ontology
	}
}
created() {
    this.getEntity();  // 获取实体页面
    this.getOntoList();  // 获取本体名称列表
},
  methods: {
      // 获取本体名称列表
      getOntoList(){
          const { kb_id } = this.$store.state;
          ctrlOntology({action:'list', params: { pageSize:100, pageNum:1, dbId: kb_id }})
          .then(res => {
              res.items.forEach(item => {
                  var obj = {}
                  obj.onto_name = item['本体']
                  obj.onto_key = item._key
                  this.ontoList.push(obj)
              })
              console.log(this.ontoList)
          })
      },

      // 下拉框选择本体跳转到相应的实体列表
      changeOnto(ontologyNamey) {
          // 将本体名称和本体key传入store
        //   this.$store.commit("SET_ONTO_NAME", ontology);
        //   this.$store.commit("SET_ONTO_KEY", row._key);

          this.getEntity()
      }
}

有个小问题, created里localstorage存储的数据还没有加载过来, router传的参数是已经加载了的.

你可能感兴趣的:(前端,el-select,下拉框)