美文网首页
vue第六章

vue第六章

作者: 久伴我者付宝宝 | 来源:发表于2018-09-22 10:13 被阅读0次

1.父给子传值 属性 props:['属性']

2.子给父传 用事件传 $emit

子给父传:

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>Document</title>

</head>

<body>

  <div id='app'>

      <my-father></my-father>

  </div>

  <script src='js/vue.js'></script>

  <script>

      Vue.component("my-father",{

          template:`

            <div>

              <h1>{{mess}}</h1>

              <my-child @send='rcvMsg'></my-child>

            </div>

          `,

          data:function(){

              return{

                  mess:''

              }

          },

          methods:{

              rcvMsg:function(txt){

                  this.mess=txt

              }

          }

      })

      Vue.component('my-child',{

          template:`

                <button @click='sendToFather'>传给父元素</button>

            `,

          data:function(){

              return{

                  msg:'我是子组件中的数据,要给父组件传值'

              }

          },

          methods:{

            sendToFather:function(){

//                this.$emit('自定义事件名',要传输的数据)

                  this.$emit('send',this.msg)

            } 

          }

      })

      new Vue({

          el:"#app"

      })

    </script>

</body>

</html>

相关文章

  • Vue基础篇(六)

    本教程分为三部分 : 基础 进阶 实战 ,深入浅出Vue.js基础篇持续 更新中........ 第六章 表单与v...

  • 《岳响河》目录 第六章

    第六章1 第六章2 第六章3 第六章4 第六章5 第六章6 第六章7 第六章8 第六章9 第六章10 第六章11 ...

  • vue第六章

    1.父给子传值 属性 props:['属性'] 2.子给父传 用事件传 $emit 子给父传:

  • Vue 慕课网的学习 0607

    今天花了多少时间在编程的学习上: 6 今天完成的事情: 慕课网vue项目的学习 , 今天看到了第六章的第三节 , ...

  • 2019.3.11

    第六章,44,45第六章全部听完了

  • 在官网首页如何打开指南的pdf

    vue版本:"vue": "^2.6.14" vue-pdf版本:"vue-pdf": "^4.2.0"、"vue...

  • 《记忆错觉》DAY3

    【摘录】 第五章p96 第五章p110 第六章p117 第六章p119 第六章123 第六章p126 【感想】 发...

  • 【基础】Vue安装

    Vue安装 Vue官网:http://unpkg.com/vue 引入vue Vue数据渲染html {...

  • vue基础知识

    new Vue() 创建 Vue 实例,其中 Vue.components() 也可以创建 Vue 实例。 Vue...

  • Vue学习总结(2019.7.31-8.4)

    Vue学习总结 目录 vue基础知识(1-13)vue 引入,实例化vue 数据 & 方法vue 绑定(:)vue...

网友评论

      本文标题:vue第六章

      本文链接:https://www.haomeiwen.com/subject/mcitoftx.html