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

vue?內(nèi)置組件?component?的用法示例詳解

 更新時(shí)間:2022年08月04日 14:12:15   作者:EncodingAESKey  
這篇文章主要介紹了vue內(nèi)置組件component的用法,本文給大家介紹了component內(nèi)置組件切換方法,通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

component is 內(nèi)置組件切換方法一:

component組件(單獨(dú)拿出一個(gè)組件來(lái)專(zhuān)門(mén)進(jìn)行切換使用)

使用is來(lái)綁定你的組件:如下面的reviewedPlan planDetailsList attachmentList等引入的組件名

changeViewFun 是用來(lái)切換組件的方法 通過(guò)給is綁定的currentView來(lái)實(shí)現(xiàn)切換組件

pathUrl就是當(dāng)前的路由

<template>
    <div class="reviewed">
        <component
            :is="currentView"
            @changeview="changeViewFun"
            :pathUrl="pathUrl"
        ></component>
    </div>
</template>
<script>
     //引入三個(gè)需要切換的組件
    import reviewedPlan from '../modules/reviewedPlan.vue';
    import planDetailsList from './planDetailsList';
    import attachmentList from './attachmentList.vue';
    export default {
        name: "reviewed",
        data() {
            return {
                currentView:'reviewedPlan',
                pathUrl:'',
                hrefIndex:"",
            }
        },
        components: {
            reviewedPlan,
            planDetailsList,
            attachmentList
        },
        created () {
              this.hrefIndex=window.location.href.indexOf('jxjh')-1;
              this.pathUrl=window.location.href.substring(this.hrefIndex);
              if(this.$route.query.currentView){
                  this.$route.query.currentView = this.$route.query.currentView===this.currentView?this.$route.query.currentView:this.currentView;
              }
          },
        methods:{
          //組件切換方法
            changeViewFun(val){
                this.currentView = val;
            }
        },
    }
</script>
<style lang="less" scoped>
    @import "~@/libs/less/theme/theme.less";
 
</style>

每個(gè)切換的組件

this.$emit("changeview","planDetailsList");  //父組件監(jiān)聽(tīng)到changeview,給is綁定的currentView重新賦值
this.$router.push({
       path: this.pathUrl,  //通過(guò)props接收  props:{pathUrl:String}
       query: {
          id: params.row.id,   //參數(shù)名
          from:"reviewedPlan"  //這里加from原因是要區(qū)分多個(gè)組件的情況下通過(guò)路由from參數(shù)來(lái)區(qū)分是通過(guò)那個(gè)組件切換過(guò)來(lái)的
       }
 })

返回組件內(nèi)部方法 (點(diǎn)擊返回的時(shí)候執(zhí)行的操作)

var url =  this.$route.query.from;  //取路由from,區(qū)分是那個(gè)通過(guò)那個(gè)組件傳遞過(guò)來(lái)的,返回的時(shí)候可返回到對(duì)應(yīng)的組件
this.$emit("changeview",url);
this.$router.push({
      path: this.pathUrl,
      query: {
             currentView:url,
        }
})

component is 內(nèi)置組件切換方法二:

實(shí)現(xiàn)的結(jié)果是:組件A調(diào)轉(zhuǎn)組件B,組件A里面有個(gè)查看按鈕,點(diǎn)擊查看,跳轉(zhuǎn)到組件B,組件B里面點(diǎn)擊返回跳轉(zhuǎn)到組件A,使用component,從組件A跳到組件B,在組件B里面刷新之后還是停留在組件B,還有就是點(diǎn)擊tab切換的時(shí)候也可以,點(diǎn)擊那個(gè)tab,當(dāng)前tab發(fā)請(qǐng)求。具體實(shí)現(xiàn):

1、封裝routePlugin.js插件

const addQuery=function(queryDate){
    var query={};
    Object.assign(query,this.$route.query,queryDate);
    this.$router.push({
        path:this.$route.path,
        query:query
    });
};
const delQuery=function(){
    var query={};
    var arg=Array.prototype.slice.call(arguments);
    Object.assign(query,this.$route.query);
    arg.forEach(item=>{
        delete query[item];//刪除參數(shù)
    })
    this.$router.push({
        path:this.$route.path,
        query:query
    });
};
var install = {
    install(Vue) {
        Vue.mixin({
            beforeCreate() {
                var self=this;
                this.$routePlugin={
                    addQuery:addQuery.bind(self),
                    delQuery:delQuery.bind(self)
                }
            }
        })
    }
}
export default install;

2、在main.js中注冊(cè)到全局,
import routePlugin from "./libs/js/vueExtend/routePlugin.js";

Vue.use(routePlugin); //修改參數(shù)方法

3、在組件內(nèi)部使用

說(shuō)明:需要三個(gè)組件:第一個(gè):component主控制組件、第二個(gè):初始化組件內(nèi)容、第三個(gè):跳轉(zhuǎn)過(guò)去的組件

第一個(gè):studentIndex.vue

<template>
    <component
        :is="viewName"
        @updateView="updateView"
    >
    </component>
</template>
<script>
 
import studentGrowthPortfolio from './studentGrowthPortfolio.vue';  //學(xué)生 index
import fileDetails from './fileDetails.vue';  //成長(zhǎng)檔案 詳情
export default {
    data(){
        return{
            viewName:"studentGrowthPortfolio",
        }
    },
    components:{
        studentGrowthPortfolio,
        fileDetails
    },
    mounted(){
        this.viewName=this.$route.query.viewName?this.$route.query.viewName:this.viewName;
    },
    created () {
    },
    methods:{
        /**
         * 接收子組件數(shù)據(jù)
         * @param data {Object}
         * @return {Void} 無(wú)
         */
         updateView(name){
             this.viewName = name
             if(!name){
                 this.$routePlugin.delQuery('viewName');
             }else{
                 this.$routePlugin.addQuery({viewName:name});
             }
         },
    },
}
</script>
<style scoped lang="less">
    @import "~@/libs/less/theme/theme.less";
 
</style>

4、第二個(gè):studentGrowthPortfolio.vue,點(diǎn)擊查看需要執(zhí)行的代碼

click: () => {
        this.$emit("updateView","fileDetails");
        this.$routePlugin.addQuery({
               viewName:'fileDetails',
               identity:'student'
          })
 }

5、第三個(gè):fileDetails.vue,點(diǎn)擊返回時(shí)需要執(zhí)行的代碼

click:()=>{
     this.$emit('updateView', 'studentGrowthPortfolio')
}

fileDetails.vue添加beforeDestoy,當(dāng)離開(kāi)當(dāng)前組件時(shí),銷(xiāo)毀路由上的identity,和viewName參數(shù)

beforeDestroy(){

            this.$routePlugin.delQuery('identity','viewName')
 },

到此這篇關(guān)于vue內(nèi)置組件component的用法的文章就介紹到這了,更多相關(guān)vue內(nèi)置組件component內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

山东省| 沾化县| 论坛| 凉城县| 桂平市| 伊川县| 丰镇市| 和林格尔县| 霍林郭勒市| 老河口市| 新邵县| 通榆县| 兴宁市| 罗江县| 琼中| 门头沟区| 津市市| 措美县| 宜黄县| 贡嘎县| 邵阳县| 绍兴市| 葫芦岛市| 盐源县| 厦门市| 个旧市| 黄平县| 钟祥市| 黔南| 永嘉县| 珠海市| 翁牛特旗| 黄浦区| 越西县| 沿河| 罗江县| 迁西县| 项城市| 吐鲁番市| 利川市| 陕西省|