在render函數中如何實現v-model


export default{
    data(){
        return{
        }
    },
    render(h){
        let that=this;//為了防止this的指向發生改變
        console.log("render中的this", this);//Proxy {}對象
        return h('input',{
            // wa你想咋個命名就怎樣
            wa:{
                value: that.value,//獲取值
            },
            // 事件on,用來監聽input事件
            on:{
                'input':function(event){
                    that.$emit('input',event.target.value)
                }
            }
        }
       );
    }
}

在使用的頁面中

import aa from "./myrender"
  
   <aa v-model="name"></aa>
   {{name}}

  data(){
     return{
         name:"",
     }
  }

 components:{
     aa
 }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM