【vue,關於$emit等的用法學習】

1. $ref—>在vue中用來“定位標籤

 <Form :label-width="100" ref="test" :model="incidentalExFormData" inline> </Form>
 使用:this.$refs.test

2. $emit—>在vue中用來:子組件可以使用 $emit 觸發父組件的自定義事件。(就是說子組件將事件傳遞給父組件,讓父組件去調用)

【子組件示例】
<Button type="primary" @click="seachSubmit">查詢</Button>
 seachSubmit: function() {
      this.pathList = "";
	      if (this.formSeach.areaId != "" && this.formSeach.areaId != null) {
	        this.pathList += "projectId=" + this.formSeach.areaId + "&";
	      }
	       this.$emit("queryData", this.pathList);
     }
【父組件示例】
<QueryMulti v-on:queryData="queryList" v-on:exportList="exportData"></QueryMulti>

3.$set()的正確使用方式—>用來給data對象新增屬性,並觸發視圖更新(解決數據已跟新,但界面沒有更新)

【正確寫法示例:this.$set(this.data,”key”,value’)】
 mounted () {
 	//代碼中使用
    this.$set(this.student,"age", 24)
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章