Vue-初始组件应用

index.html

<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/vue"></script>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <!--vue-app是根容器-->
    <h1>初始Vue组件</h1>
    <div id="vue-app-one">
        <greeting></greeting>
    </div>
    <div id="vue-app-two">
        <greeting></greeting>
    </div>
    <script src="app.js"></script>
</body>
</html>

app.js

Vue.component("greeting",{
    template:"<p>{{name}}:大家好!!!<button v-on:click='changeName'>改名</button></p>",
    data:function () {
        return {
            name:"Miracle"
        }
    },
    methods:{
        changeName:function () {
            this.name="AAAAA"
        }
    }
});

new Vue({
    el:"#vue-app-one",
});

new Vue({
    el:"#vue-app-two",
});

猜你喜欢

转载自blog.csdn.net/qq_42991834/article/details/90214232