简单入门Vue前端框架

目录

一Vue概述:

1.1MVVM模型

1.2插值表达式

二快速入门案例

三Vue常用指令:

四Vue小案例

五Vue的生命周期:

​mounted

总结:


一Vue概述:

1.1MVVM模型

1.2插值表达式

插值表达式是vue框架提供的一种在html模板中绑定数据的方式,使用{{变量名}}方式绑定Vue实例中data中的数据变量。会将绑定的数据实时的显示出来。

语法:

vue模板的表达式为{{ 变量 }}

注意:

表达式中不能定义变量或函数,也不可以写 if 条件或循环

二快速入门案例

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.8/vue.min.js"></script>
</head>
<body>
    
    <div id="app">
        <input type="text" v-model="message">
        {{message}}
    </div>
<script>
    new Vue({
        el:'#app',
        data:{
            message:'hello world'
        }
    })
</script>
</body>
</body>
</html>

三Vue常用指令:

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>v-bind,v-model</title>
    <script src ="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.8/vue.min.js" ></script>
</head>
<body>
    <div id = "app">
        <a v-bind:href ="url">百度</a>
        <input type="text" v-model="url"> 
    </div>
</body>
<script>
    new Vue({
        el: "#app",
        data:{
            url:"https://www.baidu.com"
        }

    })
</script>
</html>
html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>v-on</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.8/vue.min.js"></script>
</head>
<body>
    <div id="body">
    <input type="button" value="点击" v-on:click="say(message)">
    </div>
</body>
<script>
    new Vue({
        el:'#body',
        data:{
            message:'hello vue.js'
        },
        methods:{
            say:function(message){
                alert(message)
            }
        }
    })
</script>
</html>

四Vue小案例

通过Vue完成表格数据的渲染展示

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue Case</title>
    <script src ="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.8/vue.min.js" ></script>
</head>
<body>
    <div id="app">
        <table border="1" cellspacing="0" width="60%">
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>年龄</th>
        <th>性别</th>
        <th>成绩</th>
        <th>等级</th>
    </tr>
<tr align= "content" v-for="(user1,index) in user" >

    <td>{{index+1}}</td>
    <td>{{user.name}}</td>
    <td>{{user.age}}</td>
    <td>{{user.gender==1?"男":"女"}}</td>
    <td>{{user.score}}</td>
    <td>{{user.score>=90?"优秀":user.score>=80?"良好":user.score>=70?"一般":"不及格"}}</td>

</tr>

        </table>
    </div>
</body>
<script>
    new Vue({
        el:"#app",
        data:{
            user:[{
                name:"张三",
                age:30,
                gender:1,
                score:88
            },
            {
                name:"李四",
                age:24,
                gender:0,
                score:95
            },
            {
                name:"王五",
                age:28,
                gender:1,
                score:92
            },
            {
                name:"赵六",
                age:22,
                gender:0,
                score:89
            },
            {
                name:"钱七",
                age:35,
                gender:1,
                score:91
            }]
        }
    })
</script>

</html>

五Vue的生命周期:

mounted

总结:

相关推荐
爱学习的程序媛7 分钟前
【Web前端】Vue2与Vue3核心概览与优化对比
前端·javascript·vue.js·typescript
li@h21 分钟前
如何在电脑端访问小程序时在胶囊添加一个全屏和缩放功能
前端
LFly_ice1 小时前
学习React-23-React-router
前端·学习·react.js
我叫张小白。1 小时前
TypeScript对象类型与接口:构建复杂数据结构
前端·javascript·typescript
墨客希2 小时前
如何快速掌握大型Vue项目
前端·javascript·vue.js
大福ya2 小时前
AI开源项目改造NextChat(ChatGPT-Next-Web)实现前端SSR改造打造一个初始框架
前端·chatgpt·前端框架·开源·aigc·reactjs·ai编程
n***33352 小时前
SpringBoot返回文件让前端下载的几种方式
前端·spring boot·后端
纯粹的热爱2 小时前
🌐 阿里云 Linux 服务器 Let's Encrypt 免费 SSL 证书完整部署指南
前端
北辰alk2 小时前
Vue3 自定义指令深度解析:从基础到高级应用的完整指南
前端·vue.js
AAA阿giao2 小时前
使用 Vite + Vue 3 搭建项目并配置路由的全流程(含国内镜像加速)
vue.js·node.js·vite