zoukankan      html  css  js  c++  java
  • 前端mac地址组件

    <template>
    <div >
    <!-- <el-form-item
    :prop="input"
    :rules="rulesCheck.MAC"
    >-->
    <el-input
    @keydown.native="wat($event)" @change="wat2" :maxlength="17" v-model="input" placeholder="输入MAC地址"></el-input>
    <!-- </el-form-item>-->

    </div>
    </template>

    <script>
    export default {
    name: 'HelloWorld',
    data () {
    return {
    input:this.value,
    }
    },
    props: {
    value: {
    type: String
    }//接受外部v-model传入的值
    },
    watch:{
    //判断下拉框的值是否有改变
    value(val) {
    this.input = val;//②监听外部对props属性value的变更,并同步到组件内的data属性svalue中
    },
    input(val, oldVal) {
    this.$emit('input', this.input);
    },
    },
    mounted(){
    },
    methods:{
    wat2(){
    this.$emit('input', this.input);
    if(this.input.length == '2' || this.input.length == '5' || this.input.length == '8'|| this.input.length == '11'|| this.input.length == '14') {

    this.input = this.input + '-'
    this.$emit('input', this.input);
    return;

    if (this.input.length == '3' || this.input.length == '6' || this.input.length == '9' || this.input.length == '12' || this.input.length == '15') {
    this.input = this.input.slice(0, this.input.length - 1)
    }
    return
    }
    },
    //这个方法是老版本已废弃
    wat(val){
    this.$emit('input', this.input);
    if(this.input.length == '2' || this.input.length == '5' || this.input.length == '8'|| this.input.length == '11'|| this.input.length == '14'){
    if(val.keyCode !== 8&&val.keyCode !== 16&&val.keyCode !== 186&&val.keyCode !== 189&&val.keyCode !== 229){
    this.input = this.input + '-'
    this.$emit('input', this.input);
    return ;
    }
    if(this.input.length == '3'||this.input.length == '6'||this.input.length == '9'||this.input.length == '12'||this.input.length == '15'){
    this.input = this.input.slice(0,this.input.length-1)
    }
    return
    }
    /* if(val.keyCode == 8 && ){
    this.input = this.input.slice(0,this.input.length-1)
    }
    if(val.keyCode == 8 && this.input.length == '6' ){
    this.input = this.input.slice(0,this.input.length-1)
    }
    if(val.keyCode == 8 && this.input.length == '9' ){
    this.input = this.input.slice(0,this.input.length-1)
    }*/
    },

    check_num(){
    console.log(this.input.replace(/[^a-zA-0-9]/g, ''))
    }
    },
    }
    </script>

    <!-- Add "scoped" attribute to limit CSS to this component only -->
    <style scoped>
    h1, h2 {
    font-weight: normal;
    }
    ul {
    list-style-type: none;
    padding: 0;
    }
    li {
    display: inline-block;
    margin: 0 10px;
    }
    a {
    color: #42b983;
    }
    </style>
  • 相关阅读:
    Python迭代器的反复使用
    快速求幂模运算实现
    rural lifestyle & city lifestyle
    Python实现 扩展的欧几里德算法求(模逆数)最大公约数
    jupyter themes一行命令设置个人最爱界面
    python数组、矩阵相乘的多种方式
    有一组整型数,其中除了2个数字以外的其它数字都是俩俩成对出现的,编写程序找出这2个不成对出现的数字。
    Linux线程池技术处理多任务
    编写函数求两个整数 a 和 b 之间的较大值。要求不能使用if, while, switch, for, ?: 以 及任何的比较语句。
    C++const类型的引用参数
  • 原文地址:https://www.cnblogs.com/wplcc/p/11578626.html
Copyright © 2011-2022 走看看