zoukankan      html  css  js  c++  java
  • vue render 使用

    父组件:

    <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>
        }
    }
  • 相关阅读:
    集合赋值及for循环删除符合条件的元素
    shiro系列12:rememberme(记住我)
    shiro系列11:缓存
    shiro系列10:会话管理
    shiro系列8:授权源码解析
    shiro系列7:拦截器
    shiro系列6:授权
    shiro系列5:Realm
    shiro系列4:认证源码解析
    shiro系列3:MD5盐值加密认证流程
  • 原文地址:https://www.cnblogs.com/mary-123/p/12395361.html
Copyright © 2011-2022 走看看