<bdo id='3xx3M'></bdo><ul id='3xx3M'></ul>

        <i id='3xx3M'><tr id='3xx3M'><dt id='3xx3M'><q id='3xx3M'><span id='3xx3M'><b id='3xx3M'><form id='3xx3M'><ins id='3xx3M'></ins><ul id='3xx3M'></ul><sub id='3xx3M'></sub></form><legend id='3xx3M'></legend><bdo id='3xx3M'><pre id='3xx3M'><center id='3xx3M'></center></pre></bdo></b><th id='3xx3M'></th></span></q></dt></tr></i><div id='3xx3M'><tfoot id='3xx3M'></tfoot><dl id='3xx3M'><fieldset id='3xx3M'></fieldset></dl></div>
      1. <legend id='3xx3M'><style id='3xx3M'><dir id='3xx3M'><q id='3xx3M'></q></dir></style></legend>

        <small id='3xx3M'></small><noframes id='3xx3M'>

        <tfoot id='3xx3M'></tfoot>
      2. 关于vue.js中this.$emit的理解使用

        关于vue.js中this.$emit的理解与使用攻略
          <tbody id='AEpvt'></tbody>

          <tfoot id='AEpvt'></tfoot>

          1. <small id='AEpvt'></small><noframes id='AEpvt'>

              <bdo id='AEpvt'></bdo><ul id='AEpvt'></ul>
                  <i id='AEpvt'><tr id='AEpvt'><dt id='AEpvt'><q id='AEpvt'><span id='AEpvt'><b id='AEpvt'><form id='AEpvt'><ins id='AEpvt'></ins><ul id='AEpvt'></ul><sub id='AEpvt'></sub></form><legend id='AEpvt'></legend><bdo id='AEpvt'><pre id='AEpvt'><center id='AEpvt'></center></pre></bdo></b><th id='AEpvt'></th></span></q></dt></tr></i><div id='AEpvt'><tfoot id='AEpvt'></tfoot><dl id='AEpvt'><fieldset id='AEpvt'></fieldset></dl></div>

                  <legend id='AEpvt'><style id='AEpvt'><dir id='AEpvt'><q id='AEpvt'></q></dir></style></legend>

                • 关于vue.js中this.$emit的理解与使用攻略

                  什么是this.$emit?

                  在Vue.js中,this.$emit()是一个特殊的方法,用于定制组件的自定义事件。

                  在子组件中使用this.$emit(eventName, data)可以触发父组件的自定义事件,这样父组件就能够在监听到该事件后进行相应的处理。

                  this.$emit使用方法

                  在Vue.js中,使用this.$emit有两个参数:

                  • eventName (必选):自定义事件的名称,可以是任何字符串,但最好遵循驼峰式命名的规范。

                  • data (可选):传递给父组件的数据。

                  下面是一个用法示例:

                  Vue.component('child-component', {
                    template: `
                    <div>
                      <button @click="notify">触发自定义事件</button>
                    </div>
                    `,
                    methods: {
                      notify() {
                        this.$emit('custom-event');
                      }
                    }
                  })
                  
                  new Vue({
                    el: '#app',
                    methods: {
                      handleCustomEvent() {
                        alert('自定义事件被触发了!');
                      }
                    }
                  })
                  

                  在这个示例中,我们定义了一个子组件child-component,其中包含一个按钮,当按钮被点击时,调用notify()方法并触发'custom-event'自定义事件。在父组件中,绑定'custom-event'自定义事件并在handleCustomEvent()方法中处理。

                  this.$emit实现父子组件之间通信的案例

                  下面这个示例展示了在父子组件之间通过this.$emit来进行通信的方法。

                  父组件 App.vue 代码:

                  <template>
                    <div id="app">
                      <h1>父组件</h1>
                      <ChildComponent @childEvent="handleChildEvent"></ChildComponent>
                      <div v-if="show">
                        子组件触发了自定义事件!
                      </div>
                    </div>
                  </template>
                  
                  <script>
                  import ChildComponent from './components/ChildComponent.vue';
                  
                  export default {
                    name: 'App',
                    components: {
                      'ChildComponent': ChildComponent
                    },
                    data() {
                      return {
                        show: false
                      }
                    },
                    methods: {
                      handleChildEvent() {
                        this.show = true;
                      }
                    }
                  }
                  </script>
                  

                  子组件 ChildComponent.vue 代码:

                  <template>
                    <div>
                      <h2>子组件</h2>
                      <button @click="emitEvent">触发自定义事件</button>
                    </div>
                  </template>
                  
                  <script>
                  export default {
                    name: 'ChildComponent',
                    methods: {
                      emitEvent: function() {
                        this.$emit('childEvent');
                      }
                    }
                  }
                  </script>
                  

                  在这个案例中,子组件中的按钮被点击时,调用emitEvent方法,触发'childEvent'自定义事件。在父组件中,监听到'childEvent'自定义事件后,调用handleChildEvent方法将show的值设置为true,这样就可以在页面中看到"子组件触发了自定义事件!"这个提示了。

                  通过这个案例可以发现,this.$emit方法非常方便,能够实现父子组件之间的通信,同时也能够通过传递数据来传递信息。

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  layui实现图片上传成功后回显点击放大图片功能,html代码部分: !-- html代码--div class="layui-form-item" label class="layui-form-label"上传图片/label div class="layui-input-block" button type="button" class="layui-btn" id="license-auth-letter-
                  Layui实现数据表格中鼠标悬停图片放大离开时恢复原图的效果,最终效果如下图所示: 实现代码如下,在done函数中调用hoverOpenImg方法 var tableIns = window.demoTable = table .render({ elem : '#idTest', id : 'idTest', url : '/postData', //width : 150
                  我们在用到layui时候,需要点击文本输入框调起弹出选择框并选择内容,这个要怎么操作呢?以下两种方法可以参考: 1、点击名称,弹出信息弹框,选择表格中的某一行,实现效果如下: html页面代码 !--计量器具弹出层-- div id="equipment" lay-filter="equipmen
                  https的网站如果引用百度地图,会出现加载不了的问题,这是因为涉及到跨域问题,网站是https的,但是引用百度地图的是http的,这个要怎么操作呢? 比如我引用的地址:http://api.map.baidu.com/api?v=2.0ak=AK显示 后来看了一下,少了一个s=1字段,加一下s=1
                  做小程序项目的时候,客户提了一个功能需求优化,就是长按文字需要复制全部内容,因为有的手机支持全选复制,有的手机不支持全选复制。 通过设置系统剪贴板的内容和获取系统剪贴板的内容实现复制功能 html相关代码: van-field value="{{form.contactPhone}}"
                  由于项目功能需要,要实现对table中的行实现拖拽排序功能,找来找去发现Sortable.js能很好的满足这个需求,而且它还是开源的,于是乎就开始学习使用Sortable.js 特点 轻量级但功能强大 移动列表项时有动画 支持触屏设备和大多数浏览器(IE9及以下除外) 支持
                • <i id='IyKpO'><tr id='IyKpO'><dt id='IyKpO'><q id='IyKpO'><span id='IyKpO'><b id='IyKpO'><form id='IyKpO'><ins id='IyKpO'></ins><ul id='IyKpO'></ul><sub id='IyKpO'></sub></form><legend id='IyKpO'></legend><bdo id='IyKpO'><pre id='IyKpO'><center id='IyKpO'></center></pre></bdo></b><th id='IyKpO'></th></span></q></dt></tr></i><div id='IyKpO'><tfoot id='IyKpO'></tfoot><dl id='IyKpO'><fieldset id='IyKpO'></fieldset></dl></div>
                  <legend id='IyKpO'><style id='IyKpO'><dir id='IyKpO'><q id='IyKpO'></q></dir></style></legend>
                      <tbody id='IyKpO'></tbody>

                        <bdo id='IyKpO'></bdo><ul id='IyKpO'></ul>

                        <small id='IyKpO'></small><noframes id='IyKpO'>

                        • <tfoot id='IyKpO'></tfoot>