1. 主页
  2. 文档
  3. vue2 dcloud
  4. 第2节 创建第一个vue应用

第2节 创建第一个vue应用

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
	<div id="app">
	  {{ message }} {{name}}
	</div>
	
	<script type="text/javascript">
	var app = new Vue({
		el: '#app',
		data: {
			message: 'Hello Vue!',
			name : "Vue"
		}
	});
	</script>

</body>
</html>

//=======================================================

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="vue.js"></script>
</head>
<body>
    <div id="root">
        {{name}} {{age}}
    </div>
       <script>
        const app = new Vue({
            el:'#root',
            data:{
                name:'wulei',
                age:40
            }
        });
       </script>
</body>


</html>

============================================================

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="vue.js"></script>
</head>
<body>
    <div id="root">

    </div>
       <script>
        var data = {a:1};
        var vm = new Vue({
            el:'#root',
            data:data
        });

        vm.a == data.a;

        // $watch 监控变量的新值和老值。
        vm.$watch('a',function(lv,xv){
            console.log(lv,xv);
        });
        
        vm.a = "new data";

        console.log(vm.a === data.a);
       </script>
</body>


</html>
这篇文章对您有用吗?

我们要如何帮助您?