码迷,mamicode.com
首页 > 其他好文 > 详细

Vue 入门

时间:2019-08-26 00:03:20      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:ons   device   charset   实例   gen   idt   cmd   bsp   生成   

安装更换node源

1.安装node

2.node install nrm -g

3.nrm list

4.nrm use taobao

创建一个Vue项目&v-model双向绑定

1.创建一个空项目

2.打开cmd

npm init -y

npm install vue --save

<!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>
    <div id="app">
        <input type="text" v-model="number" >
        <h2>{{name}} create the first vue project</h2><br>
        <h2>{{number}}个小页</h2><br>
        <button type="button" @click="addNumber()">点我</button>
    </div>
    <script src="node_modules/vue/dist/vue.js"></script>
    <script>
        //生成一个vue实例
        var app=new Vue({
            el:"#app",
            data:{
                name:"steve yu",
                number:1
            },
            created(){
                this.name="lll"
            },
            methods:{
                addNumber(){
                    app.number++;
                    console.log("加了");
                }
            }
        })
    </script>
</body>
</html>

v-html&v-text

<!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>
    <div id="app">
        <span v-text="name"></span><br>
        <span v-html="name"></span>
    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script>
        var vu=new Vue({
            el:"#app",
            data:{
                name:"<h1>lala</h1>",
                age:15
            }
        })
    </script>
</body>
</html>

技术图片

 

 v-for

 

<div id="app">
        <ul>
            <li v-for="(user,index) in users">
                {{index}} - {{user.name}} : {{user.gender}} : {{user.age}}
            </li>
        </ul>
    </div>

 

 v-show

 

 <div id="app">
        <!--事件中直接写js片段-->
        <button v-on:click="show = !show">点击切换</button><br/>
        <h1 v-if="show">
            你好
        </h1>
    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script type="text/javascript">
        var app = new Vue({
            el:"#app",
            data:{
                show:true
            }
        })
    </script>

 

Vue 入门

标签:ons   device   charset   实例   gen   idt   cmd   bsp   生成   

原文地址:https://www.cnblogs.com/littlepage/p/11409954.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!