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

Vue動態(tài)組件與內(nèi)置組件淺析講解

 更新時間:2022年08月29日 10:23:42   作者:丘比特懲罰陸  
閑話少說,我們進入今天的小小五分鐘學習時間,前面我們了解了vue的組件,我們本文主要是講解vue的動態(tài)組件和內(nèi)置組件,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

一、動態(tài)組件

在vue中,有很多的組件可以掛載同一個掛載點上面,要在同一個掛載的點上的多個組件之間可以實現(xiàn)動態(tài)的切換渲染,我們可以通過內(nèi)置組件component的is屬性動態(tài)的綁定組件,然后我們就可以根據(jù)is的值來決定哪一個組件要被渲染,非常的方便。

我們通過一點簡單的實例代碼可以加深了解:

示例代碼:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>組件之間的傳遞</title>
</head>
<body>
    <div id="app">
        <h1>小小閑置網(wǎng)</h1>
<input type="radio" name="tab" value="qiubite1" v-model="cfl">王者賬號:
<img src="C:\Users\Administrator\Desktop\李寶\wangzhe.jpg" alt="" style="width: 30px;height:30px">
<input type="radio" name="tab" value="qiubite2" v-model="cfl">電話:
<input type="radio" name="tab" value="qiubite3" v-model="cfl">估價:
<component v-bind:is="cfl"></component>
</component>
    </div>
     <template id="n1">
        <div style="width: 200px;height: 200px;border: 2px solid rgb(100, 100, 196);">
            <h1>賬號</h1>
            <input type="text" placeholder="輸入你的賬號:">
        </div>
     </template>
     <template id="n2">
        <div style="width: 200px;height: 200px;border: 2px solid rgb(100, 100, 196);">
            <h1>電話</h1>
            <input type="text" placeholder="輸入你的電話:">
        </div>
     </template>
     <template id="n3">
        <div style="width: 200px;height: 200px;border: 2px solid rgb(100, 100, 196);">
            <h1>估價:</h1>
            <input type="text" placeholder="你心儀賣出的價格:">
        </div>
     </template>
    <script src="http://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    <script>
var  vm = new Vue({
    el:"#app",
    data:{cfl:"qiubite1"},
    components:{
            'qiubite1':{template:'#n1'},
            'qiubite2':{template:'#n2'},
            'qiubite3':{template:'#n3'},
    }
})
    </script>
</body>
</html>

運行結(jié)果:

我們可以看到三個按鈕的value的值設置成了組件的名字,雙向綁定cfl(懲罰陸,沒什么含義,自己亂起的)數(shù)據(jù),單擊按鈕,就可以改變value的值從而更新cfl里面的值;component組件的is屬性動態(tài)的綁定了cfl里面的值,根據(jù)這個is就知道哪個組件被渲染了。

二、內(nèi)置組件

根據(jù)上面的實例結(jié)果,我們看到了輸入框里輸入數(shù)據(jù),當你切換到別的組件的時候,原來組件的數(shù)據(jù)不會被保存,所以內(nèi)置組件可以包裹我們的動態(tài)組件,會將往期的組件進行緩存,而不是銷毀,他會把切換回去的組件緩存起來,做到保留組件狀態(tài)。

實例代碼:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>組件之間的傳遞</title>
</head>
<body>
    <div id="app">
        <h1>小小閑置網(wǎng)</h1>
<input type="radio" name="tab" value="qiubite1" v-model="cfl">王者賬號:
<img src="C:\Users\Administrator\Desktop\李寶\wangzhe.jpg" alt="" style="width: 30px;height:30px">
<input type="radio" name="tab" value="qiubite2" v-model="cfl">電話:
<input type="radio" name="tab" value="qiubite3" v-model="cfl">估價:
<keep-alive><component v-bind:is="cfl"></component></keep-alive>
</component>
    </div>
     <template id="n1">
        <div style="width: 200px;height: 200px;border: 2px solid rgb(100, 100, 196);">
            <h1>賬號</h1>
            <input type="text" placeholder="輸入你的賬號:">
        </div>
     </template>
     <template id="n2">
        <div style="width: 200px;height: 200px;border: 2px solid rgb(100, 100, 196);">
            <h1>電話</h1>
            <input type="text" placeholder="輸入你的電話:">
        </div>
     </template>
     <template id="n3">
        <div style="width: 200px;height: 200px;border: 2px solid rgb(100, 100, 196);">
            <h1>估價:</h1>
            <input type="text" placeholder="你心儀賣出的價格:">
        </div>
     </template>
    <script src="http://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    <script>
var  vm = new Vue({
    el:"#app",
    data:{cfl:"qiubite1"},
    components:{
            'qiubite1':{template:'#n1'},
            'qiubite2':{template:'#n2'},
            'qiubite3':{template:'#n3'},
    }
})
    </script>
</body>
</html>

運行結(jié)果:

以上就是Vue動態(tài)組件與內(nèi)置組件淺析講解的詳細內(nèi)容,更多關于Vue動態(tài)組件與內(nèi)置組件的資料請關注腳本之家其它相關文章!

相關文章

最新評論

九龙县| 清丰县| 精河县| 孝感市| 准格尔旗| 砚山县| 保亭| 朝阳县| 泽州县| 瓦房店市| 怀宁县| 濮阳市| 光山县| 济宁市| 张家界市| 上栗县| 阳城县| 普格县| 大埔县| 原阳县| 肃宁县| 阿拉尔市| 丁青县| 平和县| 南皮县| 滁州市| 同心县| 福安市| 湟源县| 郴州市| 普定县| 龙里县| 贺兰县| 巴中市| 台山市| 遂宁市| 乡城县| 牟定县| 柯坪县| 盈江县| 凤山县|