Home >Web Front-end >JS Tutorial >Communication between components in Vue.js

Communication between components in Vue.js

php中世界最好的语言
php中世界最好的语言Original
2018-03-13 14:14:431324browse

This time I will bring you the communication between Vue.js components. What are the precautions when using the communication between Vue.js components. The following is a practical case, let's take a look.

Communication between components in Vue.js

Pass number=99 to the subcomponent

<template>
  <div id="myapp">
    <com-a number=99></com-a>
  </div></template><script>
  import ComA from &#39;./components/a.vue&#39;
  export default {    components: {
      ComA
    }
  }</script>

In the subcomponent a.vue

<template>
  <div class="hello">
    {{hello}}
    {{ number }}  </div></template><script>
  export default {//    声明number属性//    未指定类型//    props: [&#39;number&#39;],//    指定类型
    props: {      &#39;number&#39;: [Number, String]
    },
    data () {      return {        hello: &#39;I am componnet a&#39;
      }
    }
  }</script>

Execution effect

Communication between components in Vue.js

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website Other related articles!

Recommended reading:

Vue tag attributes and conditional rendering of Vue.js

Vue.js Computed properties and data listening

The above is the detailed content of Communication between components in Vue.js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn