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

vue自定義開關(guān)組件使用詳解

 更新時(shí)間:2022年02月24日 16:24:46   作者:dd&zy  
這篇文章主要為大家詳細(xì)介紹了vue自定義開關(guān)組件的使用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue自定義開關(guān)組件的具體代碼,供大家參考,具體內(nèi)容如下

switch.vue:

<template>
? <div class="disLB">
? ? <div class="switch disLB" @click="toggleSwitch" :class="isOpen?'switch-on':''">
? ? ? <span class="disB switch-circle" :class="isOpen?'on':''"></span>
? ? </div>
? ??
? </div>
</template>

<script>
export default {
? data() {
? ? return {
? ? ? // isOpen: false
? ? }
? },
? props: ["isOpen"],
? methods: {
? ? toggleSwitch() {
? ? ? // 子組件不能直接修改父組件的數(shù)據(jù),要通過(guò)$emit
? ? ? this.$emit('changeSwitch')
? ? }
? }
??
}
</script>

<style lang="less" scoped>
? .switch {
? ? position: relative;
? ? border-radius: 20px;
? ? border: 1px solid #dfdfdf;
? ? width: 45px;
? ? height: 23px;
? ? .switch-circle {
? ? ? position: absolute;
? ? ? width: 21px;
? ? ? height: 21px;
? ? ? background-color: #fff;
? ? ? border-radius: 50%;
? ? ? border: 1px solid #dfdfdf;
? ? ? box-shadow: 0 1px 1px #ccc;
? ? }
? ? .on {
? ? ? right: 0;
? ? ? // background-color: #64bd63;
? ? ? border-color: #64bd63;
? ? ? transform: translate(X);
? ? ? transition: transform 0.5s, right 0.5s;
? ? }
? }
? .switch-on {
? ? background-color: #64bd63;
? }
</style>

在父組件中引入并傳值使用:

<template>
?? ?<toggle-switch :isOpen="systemConfig.enable_email" @changeSwitch="changeSwitch" v-model="systemConfig.enable_email"></toggle-switch>
</template>

<script>
import toggleSwitch from '../../components/switch.vue';
export default {
? ? data() {
? ? ? ? return {}
? ? },
? ? components: {
? ? ? ? toggleSwitch
? ? },
? ? methods: {
? ? ? ? changeSwitch() {
? ? ? ? ? this.systemConfig.enable_email = !this.systemConfig.enable_email;
? ? ? ? }
? ? }
}

效果圖:

注:

父組件向子組件傳值,可以直接通過(guò):isOpen="systemConfig.enable_email"傳遞數(shù)據(jù),子組件通過(guò) prop 接收數(shù)據(jù):props: ["isOpen"],;
但子組件不能直接修改父組件的數(shù)據(jù),可以通過(guò) $emit 調(diào)用父組件的方法來(lái)修改父組件的數(shù)據(jù),$emit 的第一個(gè)參數(shù)要與父組件 @ 后的名稱保持一致。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

房山区| 股票| 安丘市| 福泉市| 屏东县| 华安县| 瓦房店市| 故城县| 黄平县| 舞钢市| 驻马店市| 高雄县| 许昌市| 囊谦县| 乌拉特后旗| 广水市| 山丹县| 赤峰市| 永安市| 和林格尔县| 永宁县| 城固县| 江口县| 永胜县| 木里| 芷江| 乌兰察布市| 西乌珠穆沁旗| 株洲市| 德清县| 祁门县| 金湖县| 乌兰察布市| 达尔| 武隆县| 海丰县| 开封县| 双江| 赤壁市| 安国市| 隆回县|