在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
 }

猜你喜欢

转载自www.cnblogs.com/IwishIcould/p/12423814.html