先说步骤,再上代码,最下面有完整demo代码
1、引入vue.js文件
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
2、创建vue实例
var Vm=new Vue({
el:"#app",
data(){
return{
name:"秋石兰"
}
},
})
3、模板中使用
<div id="app">{
{
name}}</div>
4、效果
完整小demo
<!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>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
width: 100%;
height: 100%;
background-color: #888;
display: flex;
}
#app{
width: 200px;
height: 200px;
background-color: #6ff66f;
margin: auto;
color: rgb(0, 74, 143);
text-align: center;
line-height: 200px;
font-size: 50px;
}
</style>
</head>
<body>
<div id="app">{
{
name}}</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script>
var Vm=new Vue({
el:"#app",
data(){
return{
name:"秋石兰"
}
},
methods:{
},
mounted(){
}
})
</script>
</body>
</html>