$emit的用法

父组件中调用子组件时绑定事件,在子组件中使用$emit方法调用该事件并传参

父组件:

<template>
    <section>
        <h2>emit</h2>
        <code></code>
        <ul>
            <li>
                <strong>html中调用</strong>
                <emit-view @enlarge-text="postFontSize += 0.1"></emit-view>
                <div>
                    <div :style="{ fontSize: postFontSize + 'em' }">调用内建的 $emit 方法并传入事件的名字,来向父级组件触发一个事件,然后我们可以用 v-on 在博文组件上监听这个事件,就像监听一个原生 DOM 事件一样</div>
                </div>
            </li>
            <li>
                <strong>methods中调用</strong>
                <emit-view1 @enlarge-text="largeText"></emit-view1>
                <div>
                    <div :style="{ fontSize: postFontSize2 + 'em' }">调用内建的 $emit 方法并传入事件的名字,来向父级组件触发一个事件,然后我们可以用 v-on 在博文组件上监听这个事件,就像监听一个原生 DOM 事件一样</div>
                </div>
            </li>
            <li>
                <strong>使用v-model</strong>
                <emit-view2 v-model="searchText"></emit-view2>
                <code>
                    {{code}}
                </code>
                <div>
                    {{searchText}}
                </div>
            </li>
        </ul>
    </section>
</template>
<script>
import EmitView from "@/components/emit/EmitView.vue"
import EmitView1 from "@/components/emit/EmitView1.vue"
import EmitView2 from "@/components/emit/EmitView2.vue"
export default {
    components:{
        EmitView,EmitView1,EmitView2
    },
    data(){
        return{
            postFontSize:1,
            postFontSize2:1,
            searchText:'',
            code:'当用在组件上时,v-model 则会这样:<emit-view2 v-bind:value="searchText" v-on:input="searchText = $event" ></emit-view2>'
        }
    },
    methods:{
        largeText(val){
            this.postFontSize2 += val;
        }
    }
}
</script>

子组件EmitView.vue

<template>
    <div>
        <button @click="$emit('enlarge-text')">Enlarge text</button>
    </div>
</template>

子组件EmitView1.vue

<template>
    <div>
        <button @click="btn">Enlarge text</button>
    </div>
</template>
<script>
export default {
    methods:{
        btn(){
            this.$emit('enlarge-text',0.1)
        }
    }
}
</script>

子组件EmitView2.vue

<template>
    <div>
         <input v-bind:value="value" v-on:input="$emit('input', $event.target.value)" >
    </div>
</template>
<script>
export default {
    props:["value"],
    data(){
        return{
            
        }
    }
}
</script>

 

VMware vCenter Server 6.7 U3 VMware vCenter Server Appliance File size: 3.93 GB File type: iso Name: VMware-VCSA-all-6.7.0-14367737.iso Release Date: 2019-08-20 Build Number: 14367737 vCenter Server Appliance ISO. It includes the UI and CLI installer for install/upgrade/migration for VMware vCenter Server Appliance, VMware Platform Services Controller, VMware vSphere Update Manager and Update Manager Download Service (UMDS). MD5SUM: dff12f195347a61a45d3aee3278ebfca SHA1SUM: 6989f3e17278545d77251c46152c4e08e1c32db4 SHA256SUM: d0bc2c26d6313a92323ac5f8cab8838324613e6762e3a749646bac6496d4d838 VMware vCenter Server Appliance Update Bundle File size: 2.01 GB File type: zip Name: VMware-vCenter-Server-Appliance-6.7.0.40000-14367737-updaterepo.zip Release Date: 2019-08-20 Build Number: 14367737 Use this package to update from any released VMware vCenter Server Appliance 6.7 to VMware vCenter Server 6.7U3 Appliance MD5SUM: ecda33c94a71a86ab24147eb4c17eb89 SHA1SUM: 2c0759b4189f1cd4214834cdb96ec5984f059200 SHA256SUM: f1c9b4197c06fa50122d860dc51463319ae5037b9eb4ccd6c2b882d44e8fe473 VMware vCenter Server for Windows File size: 2.07 GB File type: iso Name: VMware-VIM-all-6.7.0-14367737.iso Release Date: 2019-08-20 Build Number: 14367737 Installer for VMware vCenter Server, VMware Platform Services Controller, VMware vSphere Update Manager, Update Manager Download Service (UMDS) and other vCenter Server-related modules. It enables installation of vCenter Server on Windows (Requires a 64-bit capable server). MD5SUM: 066f87b31cbfeaaf7c5777c4f3db1c01 SHA1SUM: 6aa6f192570afc89dd48e365848cbf87a87572b0 SHA256SUM: 74d758be32804856eefca00573547f001e153f2850fa815c2c2a79891432ec24 VMware vSphere Hypervisor (ESXi ISO) image (Includes VMware Tools) File size: 314.66 MB File type: iso Name: VMware-VMvisor-Installer-6.7.0.update03-14320388.x86_64.iso Release Date: 2019-08-20 Build Number: 14320388 Boot your server with this image in order to install or upgrade to ESXi (ESXi requires 64-bit capable servers). This ESXi image includes VMware Tools. MD5SUM: cafb95ae04245eb3e93fed1602b0fd3b SHA1SUM: 415f08313062d1f8d46162dc81a009dbdbc59b3b SHA256SUM: fcbaa4cd952abd9e629fb131b8f46a949844405d8976372e7e5b55917623fbe0 VMware vSphere Hypervisor (ESXi) Offline Bundle File size: 433.54 MB File type: zip Name: update-from-esxi6.7-6.7_update03.zip Release Date: 2019-08-20 Build Number: 14320388 Including VMware Tools. Use the image profiles and the VIB packages with VMware Image BuContains VIB packages MD5SUM: b3a89ab239caf1e10bac7d60277ad995 SHA1SUM: 590aabc3358c45ca7ee3702d50995ce86ac43bf8 SHA256SUM: 5a08550644574ef69f63cbedcaddc3d571eb324f31c1616526ae41ce310ec7c7
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值