Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src="https://cdn.bootcss.com/vue/2.5.13/vue.min.js"></script>
  <script src="https://cdn.bootcss.com/vuex/3.0.1/vuex.min.js"></script>
  <script src="https://cdn.bootcss.com/vue-router/3.0.1/vue-router.min.js"></script>
</head>
<body>
  <div id="app">
    <father></father>
  </div>
</body>
</html>
 
.father {
  border: 1px solid red;
  padding: 2px;
}
.child {
  border: 1px solid green;
  padding: 2px;
}
 
Vue.component('child', {
  props: ['fname'],
  template: `
    <div class="child">
      这是儿子, 我爸爸是{{fname}}
      <button @click="$emit('toFather')">点我通知爸爸</button>
    </div>
  `
})
Vue.component('father', {
  data() {
    return {
      info: '无消息'
    }
  },
  template: `
    <div class="father">
      这是父亲, {{info}}
      <child fname="father" @toFather="getSonMsg"></child>
    </div>
  `,
  methods: {
    getSonMsg() {
      this.info = '我收到儿子传来的消息了'
    }
  }
})
new Vue({
  el: '#app',
})
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
helloyongweipro
0viewers