首页
   /       /   
Vue中实现对齐方式选择组件
11月
23
Vue中实现对齐方式选择组件
作者: 大彭Sir    分类: 随手笔记     正在检查是否收录...

效果

Vue中实现对齐方式选择组件
主要使用点击给当前元素添加class

创建一个Float组件

<template>
  <div class="float">
    <div class="title">{{ title }}</div>
    <div class="right-input-wrap">
        <div class="alignMode" v-for="(item,index) in 3" :key="index">
      <span @click="checkAtv(index)" :class="[cIndex === index?'active':'','align'+(index+1)]"><em></em><em></em><em></em><em></em></span>
    </div>
    </div>
  </div>
</template>

js部分

<script>
export default {
  name: "float",
  components: {},
  props: {
    title: {
      type: String,
      default: "标题",
    },
    value: {
      type: [String, Number],
      default: "",
    },
    prop: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      cIndex: 1
    };
  },
  computed: {
  },
  watch: {},
  methods: {
    checkAtv(index){
        this.cIndex = index;
        console.log(index)
        if(index == 0){
           this.$emit("update", "left", this.prop);
        }else if(index == 1){
        this.$emit("update", "none", this.prop);
        }else if(index == 2){
        this.$emit("update", "right", this.prop);
        }
    }
  },
  created() {},
  mounted() {},
  beforeMount() {},
};
</script>

样式部分

<style lang="less"  scoped>
.alignMode span.active {
    background: #daebff;
}
.alignMode em:first-child,.alignMode em:nth-child(3) {
    width: 8px;
}
.alignMode em:nth-child(2),  .alignMode em:nth-child(4) {
    width: 100%;
}
.alignMode em:first-child, .alignMode em:nth-child(3) {
    width: 8px;
}
.alignMode em:nth-child(2), .alignMode em:nth-child(4) {
    width: 100%;
}
.alignMode .align1 {
    text-align: left;
}
.alignMode .align2 {
    text-align: center;
}
.alignMode .align3 {
    text-align: right;
}
.alignMode em {
    display: inline-block;
    vertical-align: top;
    border-top: 1px solid #333;
    margin: 1px 0;
}
.alignMode span {
    display: inline-block;
    width: 13px;
    height: 13px;
    padding: 5px;
    border-radius: 50%;
    line-height: 0;
    margin: 0 2px;
    cursor: pointer;
}
.float {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
  .left-text {
    font-size: 12px;
    color: #888;
  }
  .right-input-wrap {
    display: flex;
    flex: 1;
    justify-content: end;
    // padding-right: 10px;
    .radio {
      margin-right: 10px;
      .text {
        font-size: 12px;
      }
    }
  }
}
</style>

使用组件

引入组件(路径自己找)

import FloatVue from "../../input2/Float.vue";
export default {
  name: "home",
  components: {
    FloatVue
  },

使用

<FloatVue title="对齐方式" @update="propsStyle.float = $event" :value="propsStyle.float" ></FloatVue>
本文标签: 标签: VUE 组件
责任声明:本页信息由网友自行发布或来源于网络,真实性、合法性由发布人负责,请仔细甄别!本站只为传递信息,我们不做任何双方证明,也不承担任何法律责任。文章内容若侵犯你的权益,请联系本站删除!
转载声明:本文作者 大彭Sir,如需转载请保留文章出处!原文链接请自行复制!

评论

Theme By Brief 鄂ICP备19010459号

sitemap

首页

分类

友链