最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue實(shí)現(xiàn)按需加載組件及異步組件功能

 更新時(shí)間:2019年05月27日 16:59:56   作者:浚琦  
這篇文章主要介紹了vue實(shí)現(xiàn)按需加載組件和異步組件,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下

說實(shí)話,我一開始也不知道什么叫按需加載組件,組件還可以按需加載???后來知道了

學(xué)不完啊...沒關(guān)系,看我的

按需加載組件,或者異步組件,主要是應(yīng)用了component的 is 屬性

template中的代碼:

這里的每一個(gè)按鈕,都要顯示不同的組件,所以我讓他們使用了同一個(gè)方法名

 <template slot-scope="scope">
    <el-button
    type="text"
    size="mini"
    @click="handleSchedule('CustomerInfoSchedule', scope.row.customer_id)"
    >詳情</el-button>
    <el-button
    type="text"
    size="mini"
    @click="handleSchedule('VisitRecordSchedule', scope.row.customer_id)"
    >回訪</el-button>
    <el-button
    type="text"
    size="mini"
    @click="handleSchedule('AddCustomerSchedule',scope.row.customer_id)"
    >編輯</el-button>
    <el-button
    type="text"
    size="mini"
    @click="handleSchedule('AddPeopleSchedule', scope.row.customer_id)"
    >添加聯(lián)系人</el-button>
   </template>

 <component 
 :is="currentComponent" 
 :customer_id="customer_id" 
 @componentResult="componentResult"
 >
 </component>

script中的代碼:

這里的組件使用request按需引入,我使用的點(diǎn)擊事件,當(dāng)事件觸發(fā)的時(shí)候,引入對應(yīng)的組件

首先在data中聲明組件的屬性

 data() {
 return {
  currentComponent: "",
  customer_id:'',
 }
 }

然后注冊組件

這里的組件作為一個(gè)個(gè)方法,組件名是方法名,組件內(nèi)容是方法體,有幾個(gè)組件就寫幾個(gè)方法

components: {
  AddCustomerSchedule(resolve) {
  require(["../components/AddCustomer"], resolve);
  },
  AddPeopleSchedule(resolve) {
  require(["../components/AddPeople"], resolve);
  },
  CustomerInfoSchedule(resolve) {
  require(["../components/CustomerInfo"], resolve);
  },
  VisitRecordSchedule(resolve) {
  require(["../components/VisitRecord"], resolve);
  },
 },

定義的方法

// 這里直接接收name,然后相對應(yīng)的引入組件,同時(shí)傳值
 handleSchedule(name, id) {
  this.customer_id = id;
  this.currentComponent = name;
  },
 // 這是子組件觸發(fā)父組件返回回來的方法,因?yàn)槲业慕M件都是彈出框
 // 所以在子組件關(guān)閉彈出框的時(shí)候,我讓this.currentComponent為空
 // 同時(shí)可以選擇性的刷新數(shù)據(jù)
  componentResult(type) {
  if (type == "upData") {
   this.getTableData();
  } else {
   this.currentComponent = "";
  }
  },

總結(jié)

以上所述是小編給大家介紹的vue實(shí)現(xiàn)按需加載組件及異步組件功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論

霍邱县| 佳木斯市| 深州市| 成武县| 龙南县| 雷州市| 称多县| 阿克陶县| 郯城县| 东丽区| 翁牛特旗| 左贡县| 麟游县| 麻阳| 吴川市| 松溪县| 唐河县| 丰镇市| 闵行区| 龙泉市| 侯马市| 治多县| 钦州市| 通海县| 新蔡县| 宣化县| 比如县| 赤壁市| 河池市| 西乌珠穆沁旗| 类乌齐县| 辰溪县| 大庆市| 昭通市| 侯马市| 河池市| 龙口市| 贡觉县| 永吉县| 永顺县| 宽甸|