Creating Vue examples

Creating Vue examples

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

    <!-- View 视图 -->
    <div id="app">
        <h1>{{greeting}}</h1>
    </div>

    <script src="./vue.js"></script>
    <script>

        // Model 数据
        const model = {
            greeting: 'Hello Vuejs'
        }

        // ViewModel 使用 Vue 构造函数创建 Vue 实例
        const app = new Vue({
            // el: '#app',
            data: model
        });

        // 在没有 el 选项的情况下,需要调用 $mount 方法,手动将实例挂载到页面中的 DOM 元素上
        app.$mount('#app')

    </script>
</body>

</html>

Create multiple instances Vue

<body>

    <div id="app1">
        <h1>{{greeting}}</h1>
    </div>

    <div id="app2">
        <h1>{{greeting}}</h1>
    </div>

    <script src="./vue.js"></script>
    <script>

       
        const app1 = new Vue({
            el: '#app1',
            data: {
                greeting: 'Hello Vuejs'
            }
        });

        const app2 = new Vue({
            el: '#app2',
            data: {
                greeting: 'Hello World'
            }
        });

        // 应用程序中可以有多个 Vue 实例,它们之间是相互独立的,分别管理页面的不同部分。
        // 一般情况下,一个应用程序中只需要一个 Vue 实例即可。

    </script>
</body>
Published 151 original articles · won praise 1 · views 1883

Guess you like

Origin blog.csdn.net/qq_45802159/article/details/103816283