| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <div id="app">
- <h1 @click="clickFun">这是一个vue实例的h1标题</h1>
- <box></box>
- </div>
- <template id="box-temp">
- <div>
- <h1 @click="clickHandle">这是一个组件的h1标题</h1>
- </div>
- </template>
- <script src="./js/vue.js"></script>
- <script>
- new Vue({
- el: '#app',
- methods:{
- clickFun(){
- console.log("父组件h1被点击了");
- }
- },
- components:{
- "box":{
- template:"#box-temp",
- methods:{
- clickHandle(){
- console.log("子组件h1被点击了");
- }
- }
- }
- }
- })
- </script>
- </body>
- </html>
|