• 前端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>
  • 相关阅读:
    购买云主机时应该注意哪些事项
    wdcp的安装方法与常见问题
    推荐一些不错的计算机书籍(php c mysql linux等等)
    .htaccess详解及.htaccess参数说明【转】
    常用的7个.htaccess代码组织某个国家的IP访问
    最新ecshop v2.7.3版本去版权完全版
    javascript常用数组算法总结
    10道javascript笔试题
    Magento显示多货币,Magento 多货币设置
    Magento后台手动修改订单状态方法及手动修改方法php
  • 原文地址:https://www.cnblogs.com/wplcc/p/11578626.html
Copyright © 2020-2023  润新知