欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue.js實(shí)現(xiàn)開(kāi)關(guān)(switch)組件實(shí)例代碼

 更新時(shí)間:2022年06月22日 09:30:08   作者:小旭2021  
這篇文章介紹了vue.js實(shí)現(xiàn)開(kāi)關(guān)(switch)組件的實(shí)例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

最近開(kāi)發(fā)組件的時(shí)候,自定義開(kāi)發(fā)了開(kāi)關(guān)(switch)組件,現(xiàn)將代碼整理如下,方便日后復(fù)用。

toggle-switch.vue  

<template>
  <label role="checkbox" :class="['switch', { toggled }]">
    <input type="checkbox"
           class="switch-input"
           @change="toggle"/>
    <div class="switch-core"
         :style="{backgroundColor: toggled ? colorChecked  : colorUnchecked}">
      <div class="switch-button"
           :style="{transition: `transform ${speed}ms`,
           transform: toggled ? null: `translate3d(32px, 0px, 0px)`}">
      </div>
    </div>
    <span class="switch-label label-right"
          v-if="toggled"
          v-html="labelChecked">
     </span>
    <span class="switch-label label-left"
          v-html="labelUnchecked" v-else>
    </span>
  </label>
 
</template>
 
<script>
  export default {
    name: 'ToggleSwitch',
    data () {
      return {
        toggled: this.value,
        colorChecked: '#25b9e9',
        colorUnchecked: '#db572e',
        labelChecked: '開(kāi)',
        labelUnchecked: '關(guān)'
      }
    },
    props: {
      value: {
        type: Boolean,
        default: true
      },
      speed: {
        type: Number,
        default: 100
      }
    },
    methods: {
      toggle (event) {
        this.toggled = !this.toggled
        this.$emit('change', event)
      }
    }
  }
</script>
 
<style lang="scss" scoped>
 
  .switch {
    display: inline-block;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    user-select: none;
    font-size: 10px;
    cursor: pointer;
 
    .switch-input {
      display: none;
    }
 
    .switch-label {
      position: absolute;
      top: 0;
      font-weight: 600;
      color: white;
 
      z-index: 2;
 
      &.label-left {
        left: 10px;
        line-height: 20px;
        border-top-left-radius: 2px;
        border-bottom-left-radius:2px;
      }
 
      &.label-right {
        right: 10px;
        line-height: 20px;
        border-top-right-radius: 2px;
        border-bottom-right-radius:2px;
      }
    }
 
    .switch-core {
      display: block;
      position: relative;
      box-sizing: border-box;
      outline: 0;
      margin: 0;
      transition: border-color .3s, background-color .3s;
      user-select: none;
      width: 64px;
      height: 20px;
      border-radius: 4px;
      line-height: 20px;
 
      .switch-button {
        width: 32px;
        height: 20px;
        display: block;
        position: absolute;
        overflow: hidden;
        top: 0;
        left: 0;
        z-index: 3;
        transform: translate3d(0, 0, 0);
        background-color: #ecf0f5;
      }
    }
  }
</style>

App.vue

<template>
  <div id="app">
    <div class="left">
      <toggle-switch></toggle-switch>
    </div>
    <div class="main">
      <router-view></router-view>
    </div>
  </div>
</template>
 
<script>
  import ToggleSwitch from '@/components/toggle-switch'
  export default {
    name: 'app',
    components: {
      ToggleSwitch
    }
  }
</script>
 
<style>
  #app {
    font-family: 'Microsoft YaHei','Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: left;
    color: #2c3e50;
    height:100%;
  }
 
  .left {
    margin: 50px 200px;
  }
  .main{
    float:left;
    width:95%;
    background-color: #EFF2F7;
    height:100%;
    overflow: auto;
 
  }
</style>

到此這篇關(guān)于vue.js實(shí)現(xiàn)開(kāi)關(guān)(switch)組件的文章就介紹到這了。希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue微信分享 vue實(shí)現(xiàn)當(dāng)前頁(yè)面分享其他頁(yè)面

    vue微信分享 vue實(shí)現(xiàn)當(dāng)前頁(yè)面分享其他頁(yè)面

    這篇文章主要為大家詳細(xì)介紹了vue微信分享功能,vue實(shí)現(xiàn)當(dāng)前頁(yè)面分享其他頁(yè)面,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • vue實(shí)現(xiàn)勻速輪播效果

    vue實(shí)現(xiàn)勻速輪播效果

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)勻速輪播效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • vue后臺(tái)管理之動(dòng)態(tài)加載路由的方法

    vue后臺(tái)管理之動(dòng)態(tài)加載路由的方法

    這篇文章主要介紹了vue后臺(tái)管理之動(dòng)態(tài)加載路由的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • 如何在vue中使用HTML 5 拖放API

    如何在vue中使用HTML 5 拖放API

    這篇文章主要介紹了如何在vue中使用HTML 5 拖放API,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下
    2021-01-01
  • vue?目錄樹(shù)的展開(kāi)與關(guān)閉的實(shí)現(xiàn)

    vue?目錄樹(shù)的展開(kāi)與關(guān)閉的實(shí)現(xiàn)

    Vue作為一款流行的前端框架,提供了一種數(shù)據(jù)驅(qū)動(dòng)的方式來(lái)實(shí)現(xiàn)目錄樹(shù),本文主要介紹了vue?目錄樹(shù)的展開(kāi)與關(guān)閉的實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-11-11
  • Vue中slot插槽作用與原理詳解

    Vue中slot插槽作用與原理詳解

    插槽slot可以說(shuō)在一個(gè)Vue項(xiàng)目里面處處都有它的身影,比如我們使用一些UI組件庫(kù)的時(shí)候,我們通??梢允褂貌宀蹃?lái)自定義我們的內(nèi)容,這篇文章主要介紹了Vue3中slot插槽使用方式,需要的朋友可以參考下
    2022-09-09
  • 利用vue3+threejs仿iView官網(wǎng)大波浪特效實(shí)例

    利用vue3+threejs仿iView官網(wǎng)大波浪特效實(shí)例

    最近好幾個(gè)vue項(xiàng)目都是用ivew作為UI框架,所以下面這篇文章主要給大家介紹了關(guān)于如何利用vue3?+?threejs仿iView官網(wǎng)大波浪特效的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2021-12-12
  • vue3自定義指令看完這篇就入門(mén)了

    vue3自定義指令看完這篇就入門(mén)了

    不同于vue2不需要被use使用,vue3的機(jī)制是你的指令必須要被注冊(cè)成方法的,這樣你才能全局使用到自定義指令,下面這篇文章主要給大家介紹了關(guān)于vue3自定義指令的相關(guān)資料,需要的朋友可以參考下
    2022-11-11
  • el-menu動(dòng)態(tài)加載路由的實(shí)現(xiàn)

    el-menu動(dòng)態(tài)加載路由的實(shí)現(xiàn)

    本文主要介紹了el-menu動(dòng)態(tài)加載路由的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • 關(guān)于Vue父子組件傳參和回調(diào)函數(shù)的使用

    關(guān)于Vue父子組件傳參和回調(diào)函數(shù)的使用

    這篇文章主要介紹了關(guān)于Vue父子組件傳參和回調(diào)函數(shù)的使用,我們將某段代碼封裝成一個(gè)組件,而這個(gè)組件又在另一個(gè)組件中引入,而引入該封裝的組件的文件叫做父組件,被引入的組件叫做子組件,需要的朋友可以參考下
    2023-05-05

最新評(píng)論