码迷,mamicode.com
首页 > 其他好文 > 详细

vue render 使用

时间:2020-03-02 14:57:18      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:语法   efault   exp   点击事件   函数式   key   html   children   ext   

父组件:

<template>
    <div class="p-home">
        <p v-for="(item,i) in c" :key="i">{{ i }}:{{ item }}</p>
        <childone>
          壹号按钮
        </childone>
        <!-- 添加点击事件 -->
        <childtwo @click="handleClick">二号按钮</childtwo>
        <hTitle :id="item" v-for="item of [1,2,3]" :key="item"></hTitle>
    </div>
</template>
<script>
import childone from "./childone.js";
import childtwo from "./childtwo.js";
import hTitle from "./h-title.js";
export default {
    name: ‘home‘,
    components:{
        childone,childtwo,hTitle
    },
    methods: {
        handleClick() {
          alert(‘你点击了二号按钮‘)
        }
    }
};
</script>

子组件:

// 函数式组件 1  childone.js
export default {
    name: ‘childone‘,
    functional: true,
    render(h, context) {
        return h(‘button‘, ‘按钮‘)
    }
}
// 函数式组件 2 childtwo.js  接收子集 children
export default {
    name: ‘childtwo‘,
    functional: true,
    render(h, { props, listeners, children }) {
        return h(‘button‘,{
            attrs:props,
            on:{
                click: listeners.click
            }
        },children)
    }
}
//h-title
export default{
    name:‘h-title‘,
    data(){
        return {
            txtlists:[‘一‘,‘二‘,‘三‘]
        }
    },
    props:{
        id:{type:Number,default:1}
    },
    render(){
        //jsx语法
        const htxt = `<h${this.id}>标题${this.txtlists[this.id - 1]}</h${this.id}>`
        return <div domPropsInnerHTML={htxt}></div>
    }
}

 

vue render 使用

标签:语法   efault   exp   点击事件   函数式   key   html   children   ext   

原文地址:https://www.cnblogs.com/mary-123/p/12395361.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!