Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>动态组件与 v-once 指令</title>
  <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.js"></script>
</head>
<body>
  <div id="app">
    <child-one v-if="type === 'child-one'"></child-one>
    <child-two v-if="type === 'child-two'"></child-two>
    <button @click="handleBtnClick">change</button>
  </div>
  <script>
    Vue.component('child-one',{
      template: '<div>child-one</div>'
    })
    Vue.component('child-two',{
      template: '<div>child-two</div>'
    })
    var vm = new Vue({
      el: "#app",
      data: {
        type: 'child-one'
      },
      methods: {
        handleBtnClick: function(){
          this.type = this.type === 'child-one' ? 'child-two' : 'child-one'
        }
      }
    })
  </script>
</body>
</html>
Output

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

Dismiss x
public
Bin info
evenyaopro
0viewers