源代碼
點擊運行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Vue 測試實例 - 教程</title> <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script> </head> <body> <div id="app"> <child message="hello!"></child> </div> <script> // 注冊 Vue.component('child', { // 聲明 props props: ['message'], // 同樣也可以在 vm 實例中像 “this.message” 這樣使用 template: '<span>{{ message }}</span>' }) // 創建根實例 new Vue({ el: '#app' }) </script> </body> </html>
運行結果