總結一下做移動端項目遇到的坑

來源:互聯網
上載者:User

標籤:移動端   輸入   port   default   export   沒有   normal   new   disabled   

 

 

新上線了一個vue的移動端項目,其中用到了時間控制項,但是input[type=‘date‘]沒有placeholder屬性,網上查到的方法是<input type=‘text‘ onfocus=‘this.type="date"‘>,這種方法在ios上是沒問題的,但是在安卓上則需要點擊兩次才可以調起系統的時間控制項。因此決定自己寫個組件,解決安卓上的相容性問題。代碼如下:

<template>    <div class="date_container">      <input id="show-date" type="text" :value="date" disabled :placeholder="placeholder"/>      <input id="date" type="date" @change="changeDate"/>    </div></template><script>  export default{    data(){      let today = new Date()      return {        date: ‘‘      }    },    props:{      dateType:{        type: String,        default: ‘‘      },      defaultDate:{        type: String,        default: ‘‘      },      placeholder:{        type: String,        default: ‘點擊選擇日期‘      },      to:{        type: Object      }    },    created(){      this.date = this.defaultDate      if(!this.placeholder) {        this.placeholder = ‘點擊選擇日期‘      }    },    mounted(){    },    methods: {      input:function(e){//        alert(e.target.value);//        if (‘‘ === e.target.value) {//          this.date = ‘‘//          alert(this.date);//        }      },      changeDate: function (event) {//          alert(‘this.date==‘+this.date);//        alert(event.target.value);        this.date = event.target.value.replace(/-/g,‘.‘)        console.log(this.date);        this.$emit(‘setComponentDate‘, this.date.replace(/-/g,‘.‘) ,this.dateType,this.to)      }    }  }</script><!-- Add "scoped" attribute to limit CSS to this component only --><style scoped>  .date_container{    width:100%;    height:100%;    position:relative;    overflow:hidden;  }  .date_container input{    display:inline-block;    width:100%;    height:100%;    background: white;    position:absolute;    top:0;    text-align: center;    line-height:normal;  }  input[type=‘text‘]{    /*opacity:0.0;*/    color:#4c576f ;  }  input[type=‘datetime-local‘]{    background: paleturquoise;    opacity:0.0;  }  input[type=‘date‘]{    width:3rem;    height:100%;    background: paleturquoise;    opacity:0.0;  }  ::-webkit-input-placeholder {    color:#b3bcce;    font-size:.14rem;  }  input[disabled]{opacity:1}  .addContainer input[type=‘text‘]{    text-align: right;  }</style>

 

使用代碼為

<Date @setComponentDate="setComponentDate" dateType="start" :defaultDate="p.from_on" placeholder="請輸入" :to="{which:‘others‘,index:$index,dateType:‘from_on‘}"/>

 

總結一下做移動端項目遇到的坑

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.