<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## Vue組件通信 父子、兄弟、非父子 ### 1、父組件向子組件通信 **方法一:props** ~~~ <template> <child :msg="message"></child> </template> ~~~ ~~~ <template> <div>{{msg}}</div> </template> <script> export default { props: { msg: { type: String, required: true } } } </script> ~~~ **方法二:使用$children** 使用`$children`可以在父組件中訪問子組件。比如調用子組件的方法,并傳入值等。 ### 2、子組件向父組件通信 **方法一:使用vue事件** 父組件向子組件傳遞事件方法,子組件通過`$emit`觸發事件,回調給父組件。 ~~~ <template> <child @msgFunc="func"></child> </template> <script> import child from './child.vue'; export default { components: { child }, methods: { func (msg) { console.log(msg); // ssss } } } </script> ~~~ ~~~ <template> <button @click="handleClick">點我</button> </template> <script> export default { props: { msg: { type: String, required: true } }, methods () { handleClick () { //........ this.$emit('msgFunc', 'ssss'); } } } </script> ~~~ **方法二:使用$parent** 使用`$parent`可以訪問父組件的實例,當然也就可以訪問父組件的屬性和方法了。 ## 3、非父子組件、兄弟組件之間的數據傳遞 非父子組件通信,Vue官方推薦**使用一個Vue實例作為中央事件總線**。 意思就是將一個公共狀態保存在一個這些組件共用的一個父組件上,這樣就可以使用子組件通信父組件的方式來間接的完成通信了。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看