html页面使用vue

先说步骤,再上代码,最下面有完整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、效果

图片: [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-LsSeEcEi-1685697596231)(https://img-home.csdnimg.cn/images/20220524100510.png

完整小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>

猜你喜欢

转载自blog.csdn.net/m0_71585401/article/details/131011087
今日推荐