一篇文章带你了解网页框架——Vue简单入门

这篇文章将会介绍我们前端入门级别的框架——Vue的简单使用

如果你以后想从事后端程序员,又想要稍微了解前端框架知识,那么这篇文章或许可以给你带来帮助

温馨提醒:在学习该文章前,请先学习HTML,CSS,JavaScript,Ajax等前端知识

Vue基础

首先,我们从官方文档中可以得到下述描述:

  • Vue是一套用于构建用户界面的渐进式框架。
  • Vue的核心库只关注视图层,不仅易于上手,还便于与第三方库或既有项目整合。
  • 另一方面,当与现代化的工具链以及各种支持类库结合使用时,Vue 也完全能够为复杂的单页应用提供驱动。

其中我们需要格外注意的是:

  • Vue只负责前端页面的设计,并不能完全实现前端的所有功能

Vue主要特点:

  • 采用JavaScript框架

  • 简化Dom操作

  • 响应式数据驱动

VsCode插件推荐

在正式开始介绍Vue之前,我想向大家安利一个VsCode插件——Live Server

Live Server 插件可以同步代码和网页的更新:

  • 当你保存代码时,你的页面将会同步进行刷新,省略了手动点击页面的步骤,在开发中提供便利

Vue代码框架

首先我们需要学会Vue的基本使用

  1. 导入相关包
  1. <!--Vue为我们提供了两个版本,我们通常采用开发环境版本,具有检错功能便于学习-->
  2. <!-- 开发环境版本,包含了有帮助的命令行警告 -->
  3. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  4. <!-- 生产环境版本,优化了尺寸和速度 -->
  5. <script src="https://cdn.jsdelivr.net/npm/vue"></script>
  1. 基本框架使用
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Vue基础</title>
  8. </head>
  9. <body>
  10. <!--首先我们创建一个div,并绑定id为app-->
  11. <div id="app">
  12. <!--我们采用{{}}来调用相关Vue中的data中存放的数据-->
  13. {{ message }}
  14. </div>
  15. <!-- 导入vue:开发环境版本,包含了有帮助的命令行警告 -->
  16. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  17. <!--书写js代码-->
  18. <script>
  19. <!-- 以下为vue基本框架 new Vue({el,data,method})-->
  20. var app = new Vue({
  21. <!--el实现挂载点-->
  22. el:"#app",
  23. <!--data存放相关数据-->
  24. data:{
  25. <!--数据属性-->
  26. message:" 你好 小黑! "
  27. }
  28. })
  29. </script>
  30. </body>
  31. </html>

EL挂载点介绍

学习过Vue的基本使用后,我们先对EL挂载点做出最基本的介绍:

  • EL挂载点负责设置页面中属性与Vue属性的连接
  • EL挂载点设置后,页面属性可以调用Vue中的数据(data)和方法(method)

EL挂载点注意点:

  • Vue的作用范围在EL挂载点的本体元素以及后代元素中
  • Vue的EL挂载点可以依赖于各种选择器,例如类选择器等,但推荐使用ID选择器
  • Vue的EL挂载点不可以作用在HTML和BODY两个页面最大元素上

我们给出简单示例:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>el:挂载点</title>
  8. </head>
  9. <body id="body">
  10. <!--这里的{{ message }}不会有所显示,因为未与Vue连接-->
  11. {{ message }}
  12. <h2 id="app" class="app">
  13. <!-- 这里的{{ message }}会显示,因为属于Vue连接本体-->
  14. {{ message }}
  15. <!-- 这里的{{ message }}会显示,因为属于Vue连接后代元素-->
  16. <span> {{ message }} </span>
  17. </h2>
  18. <!-- 开发环境版本,包含了有帮助的命令行警告 -->
  19. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  20. <script>
  21. var app = new Vue({
  22. // 以下均可使用,
  23. // el:"#app",
  24. // el:".app",
  25. // el:"div",
  26. // body无法连接
  27. el:"#body",
  28. data:{
  29. message:"秋落"
  30. }
  31. })
  32. </script>
  33. </body>
  34. </html>

Data数据对象介绍

学习过Vue的基本使用后,我们对Data做出最基本的介绍:

  • Data用于存储页面元素中使用的各类属性
  • 属性可以包括各种类型,例如文本,数组等复杂类型
  • 渲染复杂类型数据时,遵循JavaScript的语法基本都可以使用

我们给出简单示例:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>data:数据对象</title>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <!--使用{{}}调用data数据-->
  12. {{ message }}
  13. <!--对象采用.来调用内部元素-->
  14. <h2> {{ school.name }} {{ school.mobile }}</h2>
  15. <ul>
  16. <!--数组采用[index]来选择内部元素-->
  17. <li>{{ campus[0] }}</li>
  18. <li>{{ campus[3] }}</li>
  19. </ul>
  20. </div>
  21. <!-- 开发环境版本,包含了有帮助的命令行警告 -->
  22. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  23. <script>
  24. var app = new Vue({
  25. el:"#app",
  26. data:{
  27. message:"你好!",
  28. school:{
  29. name:"河南师范大学",
  30. mobile:"0373-3325000"
  31. },
  32. campus:["东校区","西校区","新乡校区","平原湖校区"]
  33. }
  34. })
  35. </script>
  36. </body>
  37. </html>

Vue本地应用

在介绍了Vue的基本使用后,我们针对Vue内部的各种属性方法来做出一一介绍

每条属性或方法我们都会给出解释和相关案例

v-text

文本解释:

v-text:设置标签的文本值

代码解释:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>v-text指令</title>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <!--我们采用v-text来设置标签内文本,注意会覆盖掉内部文本,“深圳”将不再显示-->
  12. <h2 v-text="message+'!'">深圳</h2>
  13. <h2 v-text="info+'!'">深圳</h2>
  14. <!--另一种文本书写方式{{}}-->
  15. <h2>{{ message +'!'}}深圳</h2>
  16. </div>
  17. <!-- 开发环境版本,包含了有帮助的命令行警告 -->
  18. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  19. <script>
  20. var app = new Vue({
  21. el:"#app",
  22. data:{
  23. message:"河南师范大学",
  24. info:"软件学院"
  25. }
  26. })
  27. </script>
  28. </body>
  29. </html>

v-html

文本解释:

v-html:以html的格式来设置标签的文本值

代码解释:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>v-html指令</title>
  8. </head>
  9. <body>
  10. <!--v-html:设置元素的innerHTML-->
  11. <!--采用v-html后显示的是河南师范大学的加粗版,但采用v-text后显示的是<strong>河南师范大学</strong>-->
  12. <div id="app" v-html="context">
  13. </div>
  14. <!-- 开发环境版本,包含了有帮助的命令行警告 -->
  15. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  16. <script>
  17. var app = new Vue({
  18. el:"#app",
  19. data:{
  20. content:"<strong>河南师范大学</strong>"
  21. }
  22. })
  23. </script>
  24. </body>
  25. </html>

v-on

文本解释:

v-on:为元素绑定事件,可以采用@代替

代码解释:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>v-on</title>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <!--v-on:后面跟事件名 用于绑定事件 可以用@代替 后面用methods中的方法即可-->
  12. <input type="button" value="点击" v-on:click="doIt">
  13. <input type="button" value="点击" @click="doIt">
  14. </div>
  15. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  16. <script>
  17. var app = new Vue({
  18. el:"#app",
  19. methods:{
  20. doIt:function(){
  21. alert("河南师范大学");
  22. }
  23. }
  24. })
  25. </script>
  26. </body>
  27. </html>

v-show

文本解释:

v-show:根据表达值的真假,切换元素的显示和隐藏(隐藏后源代码仍存在)

代码解释:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  7. <title>v-show指令</title>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <!--点击后改变isShow的值,将isShow变为true或false,以此控制img的显示与隐藏-->
  12. <input type="button" value="切换显示状态" @click="changeIsShow">
  13. <!--点击增加年龄值-->
  14. <input type="button" value="累加年龄" @click="addAge">
  15. <!--v-show用于控制元素的存在或隐藏,这里采用isShow变量,根据isShow的值来判断是否存在-->
  16. <img v-show="isShow" src="./img/monkey.gif" alt="">
  17. <!--根据年龄值大小控制元素的存在或隐藏,只是为了表示v-show的参数需要是一个true或false的判定-->
  18. <img v-show="age>=18" src="./img/monkey.gif" alt="">
  19. </div>
  20. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  21. <script>
  22. var app = new Vue({
  23. el:"#app",
  24. data:{
  25. isShow:false,
  26. age:17
  27. },
  28. methods: {
  29. // 进行 isShow 的true或false更改
  30. changeIsShow:function(){
  31. this.isShow = !this.isShow;
  32. },
  33. addAge:function(){
  34. this.age++;
  35. }
  36. },
  37. })
  38. </script>
  39. </body>
  40. </html>

v-if

文本解释:

v-if:根据表达值的真假,切换元素的显示和隐藏(隐藏后,源代码不存在)

代码解释:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>v-if指令</title>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <!--以下操作实际效果同v-show相同,但隐藏后在页面的展示栏中无法看到源代码,属于彻底隐藏-->
  12. <input type="button" value="切换显示" @click="toggleIsShow">
  13. <p v-if="isShow">河南师范大学</p>
  14. <p v-show="isShow">河南师范大学 - v-show修饰</p>
  15. <h2 v-if="temperature>=35">热死啦</h2>
  16. </div>
  17. <!-- 开发环境版本,包含了有帮助的命令行警告 -->
  18. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  19. <script>
  20. var app = new Vue({
  21. el:"#app",
  22. data:{
  23. isShow:false,
  24. temperature:20
  25. },
  26. methods: {
  27. toggleIsShow:function(){
  28. this.isShow = !this.isShow;
  29. }
  30. },
  31. })
  32. </script>
  33. </body>
  34. </html>

v-bind

文本解释:

v-bind:设置元素的属性(比如:src,title。class)

代码解释:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>v-bind指令</title>
  8. <style>
  9. .active{
  10. border: 1px solid red;
  11. }
  12. </style>
  13. </head>
  14. <body>
  15. <!--v-bind通常可以隐藏,直接写 :属性 即可-->
  16. <div id="app">
  17. <!--这里采用v-bind设置页面图片-->
  18. <img v-bind:src="imgSrc" alt="">
  19. <br>
  20. <!--这里采用v-bind略写方式设置页面图片,后面采用 data 变量控制图片展示-->
  21. <!--同样采用v-bind控制title,class等属性,采用三元运算符来控制active-->
  22. <img :src="imgSrc" alt="" :title="imgTitle+'!!!'" :class="isActive?'active':''" @click="toggleActive">
  23. <br>
  24. <!--通过点击事件来控制class-->
  25. <img :src="imgSrc" alt="" :title="imgTitle+'!!!'" :class="{active:isActive}" @click="toggleActive">
  26. </div>
  27. <!-- 开发环境版本,包含了有帮助的命令行警告 -->
  28. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  29. <script>
  30. var app = new Vue({
  31. el:"#app",
  32. data:{
  33. imgSrc:"http://www.itheima.com/images/logo.png",
  34. imgTitle:"黑马程序员",
  35. isActive:false
  36. },
  37. methods: {
  38. toggleActive:function(){
  39. this.isActive = !this.isActive;
  40. }
  41. },
  42. })
  43. </script>
  44. </body>
  45. </html>

v-for

文本解释:

v-for:根据数据生成列表结构

代码解释:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>v-for指令</title>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <!--简单的添加删除操作,针对h2的数据-->
  12. <input type="button" value="添加数据" @click="add">
  13. <input type="button" value="移除数据" @click="remove">
  14. <ul>
  15. <!--简单v-for,参数为(数据名称[任起],下标[index]) in data数组-->
  16. <li v-for="(it,index) in arr">
  17. <!--在内部,可以使用数据名称和下标值-->
  18. {{ index+1 }}城市推荐:{{ it }}
  19. </li>
  20. </ul>
  21. <!--数组中装有对象也是同样的使用方法-->
  22. <h2 v-for="item in vegetables" v-bind:title="item.name">
  23. {{ item.name }}
  24. </h2>
  25. </div>
  26. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  27. <script>
  28. var app = new Vue({
  29. el:"#app",
  30. data:{
  31. arr:["北京","上海","广州","深圳"],
  32. vegetables:[
  33. {name:"鱼"},
  34. {name:"鸡"}
  35. ]
  36. },
  37. methods: {
  38. add:function(){
  39. this.vegetables.push({ name:"红烧鱼" });
  40. },
  41. remove:function(){
  42. this.vegetables.shift();
  43. }
  44. },
  45. })
  46. </script>
  47. </body>
  48. </html>

v-on+

文本解释:

v-on+:补充v-on的部分知识点

代码解释:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>v-on补充</title>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <!--方法中可以携带参数,正常调用即可-->
  12. <input type="button" value="点击" @click="doIt(666,'老铁')">
  13. <!--可以选取事件的部分事件做反应,例如@keyup.enter就是点击enter键生效,我们通常采用"."来表示事件限制-->
  14. <input type="text" @keyup.enter="sayHi">
  15. </div>
  16. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  17. <script>
  18. var app = new Vue({
  19. el:"#app",
  20. methods: {
  21. doIt:function(p1,p2){
  22. console.log("做it");
  23. console.log(p1);
  24. console.log(p2);
  25. },
  26. sayHi:function(){
  27. alert("吃了没");
  28. }
  29. },
  30. })
  31. </script>
  32. </body>
  33. </html>

v-model

文本解释:

v-model:实现双向绑定,便捷设置

代码解释:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>v-model指令</title>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <!--点击按钮实现setM方法-->
  12. <input type="button" value="修改message" @click="setM">
  13. <!--我们将文本内容与message数据双向绑定-->
  14. <!--当我们修改文本的值时,VsCode中的代码不会发生变化,但实际上message已经发生变化,我们将message的值单独列出来-->
  15. <input type="text" v-model="message" @keyup.enter="getM">
  16. <!--当上述message发生改变时,message本身发生变化,那么调用它的显示值也发生变化-->
  17. <h2>{{ message }}</h2>
  18. </div>
  19. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  20. <script>
  21. var app = new Vue({
  22. el:"#app",
  23. data:{
  24. message:"河南师范大学"
  25. },
  26. methods: {
  27. getM:function(){
  28. alert(this.message);
  29. },
  30. setM:function(){
  31. this.message ="软件学院";
  32. }
  33. },
  34. })
  35. </script>
  36. </body>
  37. </html>

案例:计算器

下面我们通过一个案例来巩固前面所学习的一些知识点

案例要求:

  • 我们希望通过"-"和"+"控制中间数字的大小(最小为0,最大为10)

知识点复习:

  • EL挂载点,Data数据,Methods方法
  • v-on,v-text方法

代码展示:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  7. <title>计算器</title>
  8. <!--css配置-->
  9. <style>
  10. #app {
  11. width: 480px;
  12. height: 100px;
  13. margin: 200px auto;
  14. }
  15. .input-num {
  16. margin-top: 20px;
  17. height: 100%;
  18. display: flex;
  19. border-radius: 10px;
  20. overflow: hidden;
  21. box-shadow: 0 0 4px black;
  22. }
  23. .input-num button {
  24. width: 150px;
  25. height: 100%;
  26. font-size: 40px;
  27. color: gray;
  28. cursor: pointer;
  29. border: none;
  30. outline: none;
  31. }
  32. .input-num span {
  33. height: 100%;
  34. font-size: 40px;
  35. flex: 1;
  36. text-align: center;
  37. line-height: 100px;
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <!--index主页-->
  43. <!--设置Vue的id绑定-->
  44. <div id="app">
  45. <img src="http://www.itheima.com/images/logo.png" alt="" />
  46. <!-- 计数器 -->
  47. <div class="input-num">
  48. <!--绑定事件sub-->
  49. <button @click="sub"> - </button>
  50. <!--数字展示-->
  51. <span>{{ num }}</span>
  52. <!--绑定事件add-->
  53. <button @click="add"> + </button>
  54. </div>
  55. </div>
  56. </body>
  57. </html>
  58. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  59. <!-- 编码 -->
  60. <script>
  61. /*
  62. 1. data中定义num属性,类型是数字,渲染到2个按钮中间
  63. 2. 减号绑定点击事件,对应的方法名叫sub,大于0之前递减
  64. 3. 加号绑定点击事件,对应的方法名叫add,小于0之前累加
  65. */
  66. // 创建Vue实例
  67. var app = new Vue({
  68. el: "#app",
  69. data: {
  70. // 修改的数字
  71. num:1
  72. },
  73. methods: {
  74. // 减
  75. sub:function(){
  76. // 递减
  77. if(this.num>0){
  78. this.num--;
  79. }else{
  80. alert("数字最小为0");
  81. }
  82. },
  83. // 加
  84. add:function(){
  85. // 累加
  86. if(this.num<10){
  87. this.num++;
  88. }else{
  89. alert("数字最大为10");
  90. }
  91. }
  92. }
  93. });
  94. </script>

案例:图片切换

下面我们通过一个案例来巩固前面所学习的一些知识点

案例要求:

  • 我们通过点击左右两边的图片切换符号来切换中间图片

知识点复习:

  • EL挂载点,Data数据,Methods方法
  • v-on,v-show,v-bind方法

代码展示:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  7. <title>Document</title>
  8. <!--css样式在下面单列-->
  9. <link rel="stylesheet" href="./css/index.css" />
  10. </head>
  11. <body>
  12. <div id="mask">
  13. <div class="center">
  14. <h2 class="title"><img src="./images/logo.png" alt=""> 学校环境 </h2>
  15. <!--展示图片,切换的中心点-->
  16. <img :src="imgList[index]" alt="" />
  17. <!--左转图片-->
  18. <!--添加绑定事件prev,用于图片的切换-->
  19. <!--添加v-show,当左侧无图片时,隐藏-->
  20. <a
  21. href="javascript:void(0)"
  22. @click="prev"
  23. class="left"
  24. v-show="index>0"
  25. >
  26. <img src="./images/prev.png" alt="" />
  27. </a>
  28. <!--右转图片-->
  29. <!--添加绑定事件right,用于图片的切换-->
  30. <!--添加v-show,当右侧无图片时,隐藏-->
  31. <a
  32. href="javascript:void(0)"
  33. @click="next"
  34. class="right"
  35. v-show="index<imgList.length-1"
  36. >
  37. <img src="./images/next.png" alt="" />
  38. </a>
  39. </div>
  40. </div>
  41. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  42. <script>
  43. const app = new Vue({
  44. el: "#mask",
  45. data: {
  46. // 图片元素
  47. imgList: [
  48. "./images/00.jpg",
  49. "./images/01.jpg",
  50. "./images/02.jpg",
  51. "./images/03.jpg",
  52. "./images/04.jpg",
  53. "./images/05.jpg",
  54. "./images/06.jpg",
  55. "./images/07.jpg",
  56. "./images/08.jpg",
  57. "./images/09.jpg",
  58. "./images/10.jpg",
  59. ],
  60. // 图片序号
  61. index: 0
  62. },
  63. methods: {
  64. // 上一张
  65. prev() {
  66. this.index--;
  67. },
  68. // 下一张
  69. next() {
  70. this.index++;
  71. }
  72. }
  73. });
  74. </script>
  75. </body>
  76. </html>
  1. * {
  2. margin: 0;
  3. padding: 0;
  4. }
  5. html,
  6. body,
  7. #mask {
  8. width: 100%;
  9. height: 100%;
  10. }
  11. #mask {
  12. background-color: #c9c9c9;
  13. position: relative;
  14. }
  15. #mask .center {
  16. position: absolute;
  17. background-color: #fff;
  18. left: 50%;
  19. top: 50%;
  20. transform: translate(-50%, -50%);
  21. padding: 10px;
  22. }
  23. #mask .center .title {
  24. position: absolute;
  25. display: flex;
  26. align-items: center;
  27. height: 56px;
  28. top: -61px;
  29. left: 0;
  30. padding: 5px;
  31. padding-left: 10px;
  32. padding-bottom: 0;
  33. color: rgba(175, 47, 47, 0.8);
  34. font-size: 26px;
  35. font-weight: normal;
  36. background-color: white;
  37. padding-right: 50px;
  38. z-index: 2;
  39. }
  40. #mask .center .title img {
  41. height: 40px;
  42. margin-right: 10px;
  43. }
  44. #mask .center .title::before {
  45. content: "";
  46. position: absolute;
  47. width: 0;
  48. height: 0;
  49. border: 65px solid;
  50. border-color: transparent transparent white;
  51. top: -65px;
  52. right: -65px;
  53. z-index: 1;
  54. }
  55. #mask .center > img {
  56. display: block;
  57. width: 700px;
  58. height: 458px;
  59. }
  60. #mask .center a {
  61. text-decoration: none;
  62. width: 45px;
  63. height: 100px;
  64. position: absolute;
  65. top: 179px;
  66. vertical-align: middle;
  67. opacity: 0.5;
  68. }
  69. #mask .center a :hover {
  70. opacity: 0.8;
  71. }
  72. #mask .center .left {
  73. left: 15px;
  74. text-align: left;
  75. padding-right: 10px;
  76. border-top-right-radius: 10px;
  77. border-bottom-right-radius: 10px;
  78. }
  79. #mask .center .right {
  80. right: 15px;
  81. text-align: right;
  82. padding-left: 10px;
  83. border-top-left-radius: 10px;
  84. border-bottom-left-radius: 10px;
  85. }

案例:记事本

下面我们通过一个案例来巩固前面所学习的全部知识点

案例要求:

  • 新增:书写内容,点击Enter后,便利贴放于页面
  • 删除:点击内容后方的"x"号后,该内容消失
  • 统计:统计内容数量,在左下角显示
  • 清空:点击右下角清空键,内容全部清空
  • 隐藏:当无内容时,下述记事本部分隐藏

代码展示:

  1. <html>
  2. <head>
  3. <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  4. <title>小黑记事本</title>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  6. <meta name="robots" content="noindex, nofollow" />
  7. <meta name="googlebot" content="noindex, nofollow" />
  8. <meta name="viewport" content="width=device-width, initial-scale=1" />
  9. <!--css样式在下列出-->
  10. <link rel="stylesheet" type="text/css" href="./css/index.css" />
  11. </head>
  12. <body>
  13. <!-- 主体区域 -->
  14. <section id="todoapp">
  15. <!-- 输入框 -->
  16. <header class="header">
  17. <h1>小黑记事本</h1>
  18. <!--输入栏,实现双向绑定,当点击时使用add方法-->
  19. <input v-model="inputValue" @keyup.enter="add" autofocus="autofocus" autocomplete="off" placeholder="请输入任务"
  20. class="new-todo" />
  21. </header>
  22. <!-- 列表区域 -->
  23. <section class="main">
  24. <ul class="todo-list">
  25. <!--记事主题内容,采用v-for遍历记事内容list的内容,输出在页面-->
  26. <li class="todo" v-for="(item,index) in list">
  27. <div class="view">
  28. <!--记事内容-->
  29. <span class="index">{{ index+1 }}.</span>
  30. <label>{{ item }}</label>
  31. <!--删除按钮,点击时触发remove功能,参数为当前index-->
  32. <button class="destroy" @click="remove(index)"></button>
  33. </div>
  34. </li>
  35. </ul>
  36. </section>
  37. <!-- 统计和清空 -->
  38. <!--记事本主体,当不存在记事内容时,隐藏-->
  39. <footer class="footer" v-show="list.length!=0">
  40. <span class="todo-count" v-if="list.length!=0">
  41. <!--统计值:直接采用list的长度代替-->
  42. <strong>{{ list.length }}</strong> items left
  43. </span>
  44. <!--记事本主体,当不存在记事内容时,隐藏-->
  45. <button v-show="list.length!=0" class="clear-completed" @click="clear">
  46. Clear
  47. </button>
  48. </footer>
  49. </section>
  50. <!-- 底部 -->
  51. <footer class="info">
  52. <p>
  53. <a href="http://www.itheima.com/"><img src="./img/black.png" alt="" /></a>
  54. </p>
  55. </footer>
  56. <!-- 开发环境版本,包含了有帮助的命令行警告 -->
  57. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  58. <script>
  59. var app = new Vue({
  60. // 实现Vue绑定
  61. el: "#todoapp",
  62. data: {
  63. // list表示记事内容
  64. list: ["写代码", "吃饭饭", "睡觉觉"],
  65. // 表示目前输入内容,双向绑定
  66. inputValue: "好好学习,天天向上"
  67. },
  68. methods: {
  69. // 新添方法,将输入值填入计时内容中
  70. add: function () {
  71. this.list.push(this.inputValue);
  72. },
  73. // 删除方法,删除当前下表为index的内容
  74. remove: function (index) {
  75. this.list.splice(index, 1);
  76. },
  77. // 清除方法,清除所有方法
  78. clear: function () {
  79. this.list = [];
  80. }
  81. },
  82. })
  83. </script>
  84. </body>
  85. </html>
  1. html,
  2. body {
  3. margin: 0;
  4. padding: 0;
  5. }
  6. body {
  7. background: #fff;
  8. }
  9. button {
  10. margin: 0;
  11. padding: 0;
  12. border: 0;
  13. background: none;
  14. font-size: 100%;
  15. vertical-align: baseline;
  16. font-family: inherit;
  17. font-weight: inherit;
  18. color: inherit;
  19. -webkit-appearance: none;
  20. appearance: none;
  21. -webkit-font-smoothing: antialiased;
  22. -moz-osx-font-smoothing: grayscale;
  23. }
  24. body {
  25. font: 14px "Helvetica Neue", Helvetica, Arial, sans-serif;
  26. line-height: 1.4em;
  27. background: #f5f5f5;
  28. color: #4d4d4d;
  29. min-width: 230px;
  30. max-width: 550px;
  31. margin: 0 auto;
  32. -webkit-font-smoothing: antialiased;
  33. -moz-osx-font-smoothing: grayscale;
  34. font-weight: 300;
  35. }
  36. :focus {
  37. outline: 0;
  38. }
  39. .hidden {
  40. display: none;
  41. }
  42. #todoapp {
  43. background: #fff;
  44. margin: 180px 0 40px 0;
  45. position: relative;
  46. box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
  47. }
  48. #todoapp input::-webkit-input-placeholder {
  49. font-style: italic;
  50. font-weight: 300;
  51. color: #e6e6e6;
  52. }
  53. #todoapp input::-moz-placeholder {
  54. font-style: italic;
  55. font-weight: 300;
  56. color: #e6e6e6;
  57. }
  58. #todoapp input::input-placeholder {
  59. font-style: italic;
  60. font-weight: 300;
  61. color: gray;
  62. }
  63. #todoapp h1 {
  64. position: absolute;
  65. top: -160px;
  66. width: 100%;
  67. font-size: 60px;
  68. font-weight: 100;
  69. text-align: center;
  70. color: rgba(175, 47, 47, .8);
  71. -webkit-text-rendering: optimizeLegibility;
  72. -moz-text-rendering: optimizeLegibility;
  73. text-rendering: optimizeLegibility;
  74. }
  75. .new-todo,
  76. .edit {
  77. position: relative;
  78. margin: 0;
  79. width: 100%;
  80. font-size: 24px;
  81. font-family: inherit;
  82. font-weight: inherit;
  83. line-height: 1.4em;
  84. border: 0;
  85. color: inherit;
  86. padding: 6px;
  87. border: 1px solid #999;
  88. box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
  89. box-sizing: border-box;
  90. -webkit-font-smoothing: antialiased;
  91. -moz-osx-font-smoothing: grayscale;
  92. }
  93. .new-todo {
  94. padding: 16px;
  95. border: none;
  96. background: rgba(0, 0, 0, 0.003);
  97. box-shadow: inset 0 -2px 1px rgba(0, 0, 0, 0.03);
  98. }
  99. .main {
  100. position: relative;
  101. z-index: 2;
  102. border-top: 1px solid #e6e6e6;
  103. }
  104. .toggle-all {
  105. width: 1px;
  106. height: 1px;
  107. border: none; /* Mobile Safari */
  108. opacity: 0;
  109. position: absolute;
  110. right: 100%;
  111. bottom: 100%;
  112. }
  113. .toggle-all + label {
  114. width: 60px;
  115. height: 34px;
  116. font-size: 0;
  117. position: absolute;
  118. top: -52px;
  119. left: -13px;
  120. -webkit-transform: rotate(90deg);
  121. transform: rotate(90deg);
  122. }
  123. .toggle-all + label:before {
  124. content: "❯";
  125. font-size: 22px;
  126. color: #e6e6e6;
  127. padding: 10px 27px 10px 27px;
  128. }
  129. .toggle-all:checked + label:before {
  130. color: #737373;
  131. }
  132. .todo-list {
  133. margin: 0;
  134. padding: 0;
  135. list-style: none;
  136. max-height: 420px;
  137. overflow: auto;
  138. }
  139. .todo-list li {
  140. position: relative;
  141. font-size: 24px;
  142. border-bottom: 1px solid #ededed;
  143. height: 60px;
  144. box-sizing: border-box;
  145. }
  146. .todo-list li:last-child {
  147. border-bottom: none;
  148. }
  149. .todo-list .view .index {
  150. position: absolute;
  151. color: gray;
  152. left: 10px;
  153. top: 20px;
  154. font-size: 16px;
  155. }
  156. .todo-list li .toggle {
  157. text-align: center;
  158. width: 40px;
  159. /* auto, since non-WebKit browsers doesn't support input styling */
  160. height: auto;
  161. position: absolute;
  162. top: 0;
  163. bottom: 0;
  164. margin: auto 0;
  165. border: none; /* Mobile Safari */
  166. -webkit-appearance: none;
  167. appearance: none;
  168. }
  169. .todo-list li .toggle {
  170. opacity: 0;
  171. }
  172. .todo-list li .toggle + label {
  173. /*
  174. Firefox requires `#` to be escaped - https://bugzilla.mozilla.org/show_bug.cgi?id=922433
  175. IE and Edge requires *everything* to be escaped to render, so we do that instead of just the `#` - https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/7157459/
  176. */
  177. background-image: url("data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23ededed%22%20stroke-width%3D%223%22/%3E%3C/svg%3E");
  178. background-repeat: no-repeat;
  179. background-position: center left;
  180. }
  181. .todo-list li .toggle:checked + label {
  182. background-image: url("data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23bddad5%22%20stroke-width%3D%223%22/%3E%3Cpath%20fill%3D%22%235dc2af%22%20d%3D%22M72%2025L42%2071%2027%2056l-4%204%2020%2020%2034-52z%22/%3E%3C/svg%3E");
  183. }
  184. .todo-list li label {
  185. word-break: break-all;
  186. padding: 15px 15px 15px 60px;
  187. display: block;
  188. line-height: 1.2;
  189. transition: color 0.4s;
  190. }
  191. .todo-list li.completed label {
  192. color: #d9d9d9;
  193. text-decoration: line-through;
  194. }
  195. .todo-list li .destroy {
  196. display: none;
  197. position: absolute;
  198. top: 0;
  199. right: 10px;
  200. bottom: 0;
  201. width: 40px;
  202. height: 40px;
  203. margin: auto 0;
  204. font-size: 30px;
  205. color: #cc9a9a;
  206. margin-bottom: 11px;
  207. transition: color 0.2s ease-out;
  208. }
  209. .todo-list li .destroy:hover {
  210. color: #af5b5e;
  211. }
  212. .todo-list li .destroy:after {
  213. content: "×";
  214. }
  215. .todo-list li:hover .destroy {
  216. display: block;
  217. }
  218. .todo-list li .edit {
  219. display: none;
  220. }
  221. .todo-list li.editing:last-child {
  222. margin-bottom: -1px;
  223. }
  224. .footer {
  225. color: #777;
  226. padding: 10px 15px;
  227. height: 20px;
  228. text-align: center;
  229. border-top: 1px solid #e6e6e6;
  230. }
  231. .footer:before {
  232. content: "";
  233. position: absolute;
  234. right: 0;
  235. bottom: 0;
  236. left: 0;
  237. height: 50px;
  238. overflow: hidden;
  239. box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2), 0 8px 0 -3px #f6f6f6,
  240. 0 9px 1px -3px rgba(0, 0, 0, 0.2), 0 16px 0 -6px #f6f6f6,
  241. 0 17px 2px -6px rgba(0, 0, 0, 0.2);
  242. }
  243. .todo-count {
  244. float: left;
  245. text-align: left;
  246. }
  247. .todo-count strong {
  248. font-weight: 300;
  249. }
  250. .filters {
  251. margin: 0;
  252. padding: 0;
  253. list-style: none;
  254. position: absolute;
  255. right: 0;
  256. left: 0;
  257. }
  258. .filters li {
  259. display: inline;
  260. }
  261. .filters li a {
  262. color: inherit;
  263. margin: 3px;
  264. padding: 3px 7px;
  265. text-decoration: none;
  266. border: 1px solid transparent;
  267. border-radius: 3px;
  268. }
  269. .filters li a:hover {
  270. border-color: rgba(175, 47, 47, 0.1);
  271. }
  272. .filters li a.selected {
  273. border-color: rgba(175, 47, 47, 0.2);
  274. }
  275. .clear-completed,
  276. html .clear-completed:active {
  277. float: right;
  278. position: relative;
  279. line-height: 20px;
  280. text-decoration: none;
  281. cursor: pointer;
  282. }
  283. .clear-completed:hover {
  284. text-decoration: underline;
  285. }
  286. .info {
  287. margin: 50px auto 0;
  288. color: #bfbfbf;
  289. font-size: 15px;
  290. text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
  291. text-align: center;
  292. }
  293. .info p {
  294. line-height: 1;
  295. }
  296. .info a {
  297. color: inherit;
  298. text-decoration: none;
  299. font-weight: 400;
  300. }
  301. .info a:hover {
  302. text-decoration: underline;
  303. }
  304. /*
  305. Hack to remove background from Mobile Safari.
  306. Can't use it globally since it destroys checkboxes in Firefox
  307. */
  308. @media screen and (-webkit-min-device-pixel-ratio: 0) {
  309. .toggle-all,
  310. .todo-list li .toggle {
  311. background: none;
  312. }
  313. .todo-list li .toggle {
  314. height: 40px;
  315. }
  316. }
  317. @media (max-width: 430px) {
  318. .footer {
  319. height: 50px;
  320. }
  321. .filters {
  322. bottom: 10px;
  323. }
  324. }

Vue网络应用

我们在本篇开头说过Vue的作用仅仅是用来完成静态页面

所以如果想要完成项目开发功能,还需要与后台交互的技术Ajax(主要采用Axios技术)

Axios技术

Axios技术是原生的Ajax进行封装,简化书写

我们在之前的Ajax专题中有完整的介绍过Ajax和Axios技术,在这里我们仅做简单回忆:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  7. <title>axios基本使用</title>
  8. </head>
  9. <body>
  10. <!--两个按钮分别用来实现两种数据获取-->
  11. <input type="button" value="get请求" class="get">
  12. <input type="button" value="post请求" class="post">
  13. <!-- 官网提供的 axios 在线地址 -->
  14. <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  15. <script>
  16. /*
  17. 接口1:随机笑话
  18. 请求地址:https://autumnfish.cn/api/joke/list
  19. 请求方法:get
  20. 请求参数:num(笑话条数,数字)
  21. 响应内容:随机笑话
  22. */
  23. // 事件绑定
  24. document.querySelector(".get").onclick = function () {
  25. // axios的get格式:get后跟url,response为返回体,err为错误
  26. axios.get("https://autumnfish.cn/api/joke/list?num=6")
  27. .then(function (response) {
  28. console.log(response);
  29. },function(err){
  30. console.log(err);
  31. })
  32. }
  33. /*
  34. 接口2:用户注册
  35. 请求地址:https://autumnfish.cn/api/user/reg
  36. 请求方法:post
  37. 请求参数:username(用户名,字符串)
  38. 响应内容:注册成功或失败
  39. */
  40. // 事件绑定
  41. document.querySelector(".post").onclick = function () {
  42. // axios的post格式:post后跟url和请求体,response为返回体,err为错误
  43. axios.post("https://autumnfish.cn/api/user/reg",{username:"盐焗西兰花"})
  44. .then(function(response){
  45. console.log(response);
  46. console.log(this.skill);
  47. },function (err) {
  48. console.log(err);
  49. })
  50. }
  51. </script>
  52. </body>
  53. </html>

Axios+Vue技术

我们常常用Vue作为页面的设计框架,同时采用Axios作为前后端交互的技术

两者的结合其实并没有互相掺杂,大致上还保留原本的形式,最大的改变只有数据来源发生变化

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>axios+vue</title>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <input type="button" value="获取笑话" @click="getJoke">
  12. <p> {{ joke }}</p>
  13. </div>
  14. <!-- 官网提供的 axios 在线地址 -->
  15. <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  16. <!-- 开发环境版本,包含了有帮助的命令行警告 -->
  17. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  18. <script>
  19. /*
  20. 接口:随机获取一条笑话
  21. 请求地址:https://autumnfish.cn/api/joke
  22. 请求方法:get
  23. 请求参数:无
  24. 响应内容:随机笑话
  25. */
  26. // 采用Vue开启框架页面
  27. var app = new Vue({
  28. el:"#app",
  29. data:{
  30. // 页面数据展示
  31. joke:"很好笑的笑话"
  32. },
  33. methods: {
  34. // 获得笑话的方法,采用axios技术进行数据请求
  35. getJoke:function(){
  36. var that = this;
  37. axios.get("https://autumnfish.cn/api/joke").then(function(response){
  38. console.log(response.data);
  39. that.joke = response.data;
  40. },function (err) { })
  41. }
  42. },
  43. })
  44. </script>
  45. </body>
  46. </html>

案例:天气预报

我们同样采用一个简单的案例来巩固Vue网络应用

案例需求:

  • 我们可以手动查找输入框内的城市的天气情况
  • 我们可以点击页面内含有的城市的天气情况

代码展示:

  1. <!--主页面展示-->
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5. <meta charset="UTF-8" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  8. <title>天知道</title>
  9. <!--CSS链接-->
  10. <link rel="stylesheet" href="css/index.css" />
  11. </head>
  12. <body>
  13. <!--Vue绑定-->
  14. <div class="wrap" id="app">
  15. <div class="search_form">
  16. <div class="logo"><img src="img/logo.png" alt="logo" /></div>
  17. <div class="form_group">
  18. <!--双向绑定city,添加事件@keyup.enter="queryWeather"-->
  19. <input type="text" class="input_txt" placeholder="请输入查询的天气" v-model="city" @keyup.enter="queryWeather" />
  20. <!--添加事件@keyup.enter="queryWeather"-->
  21. <button class="input_sub" @click="queryWeather">
  22. 搜 索
  23. </button>
  24. </div>
  25. <!--展示列出的城市,点击触发事件-->
  26. <div class="hotkey">
  27. <a href="javascript:;" v-for="city in hotCitys" @click="clickSearch(city)">{{ city }}</a>
  28. </div>
  29. <!--展示返回的天气数据-->
  30. </div>
  31. <ul class="weather_list">
  32. <!---->
  33. <li v-for="(item,index) in forecastList" :key="item.date" :style="{transitionDelay:index*100+'ms'}">
  34. <div class="info_type">
  35. <span class="iconfont">{{ item.type }}</span>
  36. </div>
  37. <div class="info_temp">
  38. <b>{{ item.low}}</b>
  39. ~
  40. <b>{{ item.high}}</b>
  41. </div>
  42. <div class="info_date">
  43. <span>{{ item.date }}</span>
  44. </div>
  45. </li>
  46. </ul>
  47. </div>
  48. <!-- 开发环境版本,包含了有帮助的命令行警告 -->
  49. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  50. <!-- 官网提供的 axios 在线地址 -->
  51. <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  52. <script>
  53. new Vue({
  54. el: "#app",
  55. data: {
  56. // 输入框城市,双向绑定
  57. city: "武汉",
  58. // 天气情况
  59. forecastList: [],
  60. // 城市展示
  61. hotCitys: ["北京", "上海", "广州", "深圳"]
  62. },
  63. methods: {
  64. queryWeather() {
  65. // 将天气情况清零
  66. this.forecastList = [];
  67. // axios获得天气状况
  68. axios
  69. .get(`http://wthrcdn.etouch.cn/weather_mini?city=${this.city}`)
  70. .then(res => {
  71. console.log(res);
  72. this.forecastList = res.data.data.forecast;
  73. })
  74. .catch(err => {
  75. console.log(err);
  76. })
  77. .finally(() => { });
  78. },
  79. // 点击城市触发queryWeather方法,获得天气情况
  80. clickSearch(city) {
  81. this.city = city;
  82. this.queryWeather();
  83. }
  84. }
  85. });
  86. </script>
  87. </body>
  88. </html>
  1. /*
  2. css展示
  3. 页面前置css修改
  4. */
  5. body,ul,h1,h2,h3,h4,h5,h6{
  6. margin: 0;
  7. padding: 0;
  8. }
  9. h1,h2,h3,h4,h5,h6{
  10. font-size:100%;
  11. font-weight:normal;
  12. }
  13. a{
  14. text-decoration:none;
  15. }
  16. ul{
  17. list-style:none;
  18. }
  19. img{
  20. border:0px;
  21. }
  22. /* 清除浮动,解决margin-top塌陷 */
  23. .clearfix:before,.clearfix:after{
  24. content:'';
  25. display:table;
  26. }
  27. .clearfix:after{
  28. clear:both;
  29. }
  30. .clearfix{
  31. zoom:1;
  32. }
  33. .fl{
  34. float:left;
  35. }
  36. .fr{
  37. float:right;
  38. }
  39. /*
  40. css展示
  41. 页面内部css修改
  42. */
  43. body{
  44. font-family:'Microsoft YaHei';
  45. }
  46. .wrap{
  47. position: fixed;
  48. left:0;
  49. top:0;
  50. width:100%;
  51. height:100%;
  52. /* background: radial-gradient(#f3fbfe, #e4f5fd, #8fd5f4); */
  53. /* background:#8fd5f4; */
  54. /* background: linear-gradient(#6bc6ee, #fff); */
  55. background:#fff;
  56. }
  57. .search_form{
  58. width:640px;
  59. margin:100px auto 0;
  60. }
  61. .logo img{
  62. display:block;
  63. margin:0 auto;
  64. }
  65. .form_group{
  66. width:640px;
  67. height:40px;
  68. margin-top:45px;
  69. }
  70. .input_txt{
  71. width:538px;
  72. height:38px;
  73. padding:0px;
  74. float:left;
  75. border:1px solid #41a1cb;
  76. outline:none;
  77. text-indent:10px;
  78. }
  79. .input_sub{
  80. width:100px;
  81. height:40px;
  82. border:0px;
  83. float: left;
  84. background-color: #41a1cb;
  85. color:#fff;
  86. font-size:16px;
  87. outline:none;
  88. cursor: pointer;
  89. position: relative;
  90. }
  91. .input_sub.loading::before{
  92. content:'';
  93. position: absolute;
  94. left: 0;
  95. top: 0;
  96. width: 100%;
  97. height: 100%;
  98. background: url('../img/loading.gif');
  99. }
  100. .hotkey{
  101. margin:3px 0 0 2px;
  102. }
  103. .hotkey a{
  104. font-size:14px;
  105. color:#666;
  106. padding-right:15px;
  107. }
  108. .weather_list{
  109. height:200px;
  110. text-align:center;
  111. margin-top:50px;
  112. font-size:0px;
  113. }
  114. .weather_list li{
  115. display:inline-block;
  116. width:140px;
  117. height:200px;
  118. padding:0 10px;
  119. overflow: hidden;
  120. position: relative;
  121. background:url('../img/line.png') right center no-repeat;
  122. background-size: 1px 130px;
  123. }
  124. .weather_list li:last-child{
  125. background:none;
  126. }
  127. /* .weather_list .col02{
  128. background-color: rgba(65, 165, 158, 0.8);
  129. }
  130. .weather_list .col03{
  131. background-color: rgba(94, 194, 237, 0.8);
  132. }
  133. .weather_list .col04{
  134. background-color: rgba(69, 137, 176, 0.8);
  135. }
  136. .weather_list .col05{
  137. background-color: rgba(118, 113, 223, 0.8);
  138. } */
  139. .info_date{
  140. width:100%;
  141. height:40px;
  142. line-height:40px;
  143. color:#999;
  144. font-size:14px;
  145. left:0px;
  146. bottom:0px;
  147. margin-top: 15px;
  148. }
  149. .info_date b{
  150. float: left;
  151. margin-left:15px;
  152. }
  153. .info_type span{
  154. color:#fda252;
  155. font-size:30px;
  156. line-height:80px;
  157. }
  158. .info_temp{
  159. font-size:14px;
  160. color:#fda252;
  161. }
  162. .info_temp b{
  163. font-size:13px;
  164. }
  165. .tem .iconfont {
  166. font-size: 50px;
  167. }

结束语

好的,关于Vue入门案例的内容就介绍到这里,希望能为你带来帮助!

附录

该文章属于学习内容,具体参考B站黑马程序员vue前端基本教程

这里附上链接:01.课程介绍_哔哩哔哩_bilibili

一篇文章带你了解网页框架——Vue简单入门的更多相关文章

  1. 一篇文章带你了解服务器操作系统——Linux简单入门

    一篇文章带你了解服务器操作系统--Linux简单入门 Linux作为服务器的常用操作系统,身为工作人员自然是要有所了解的 在本篇中我们会简单介绍Linux的特点,安装,相关指令使用以及内部程序的安装等 ...

  2. 一篇文章带你了解NoSql数据库——Redis简单入门

    一篇文章带你了解NoSql数据库--Redis简单入门 Redis是一个基于内存的key-value结构数据库 我们会利用其内存存储速度快,读写性能高的特点去完成企业中的一些热门数据的储存信息 在本篇 ...

  3. 一篇文章带你掌握主流基础框架——Spring

    一篇文章带你掌握主流基础框架--Spring 这篇文章中我们将会介绍Spring的框架以及本体内容,包括核心容器,注解开发,AOP以及事务等内容 那么简单说明一下Spring的必要性: Spring技 ...

  4. 一篇文章带你掌握主流服务层框架——SpringMVC

    一篇文章带你掌握主流服务层框架--SpringMVC 在之前的文章中我们已经学习了Spring的基本内容,SpringMVC隶属于Spring的一部分内容 但由于SpringMVC完全针对于服务层使用 ...

  5. 一篇文章带你掌握主流办公框架——SpringBoot

    一篇文章带你掌握主流办公框架--SpringBoot 在之前的文章中我们已经学习了SSM的全部内容以及相关整合 SSM是Spring的产品,主要用来简化开发,但我们现在所介绍的这款框架--Spring ...

  6. 一篇文章带你掌握主流数据库框架——MyBatis

    一篇文章带你掌握主流数据库框架--MyBatis MyBatis 是一款优秀的持久层框架,它支持自定义 SQL.存储过程以及高级映射. 在之前的文章中我们学习了MYSQL和JDBC,但是这些东西远远不 ...

  7. 一篇文章带你掌握MyBatis简化框架——MyBatisPlus

    一篇文章带你掌握MyBatis简化框架--MyBatisPlus 我们在前面的文章中已经学习了目前开发所需的主流框架 类似于我们所学习的SpringBoot框架用于简化Spring开发,我们的国人大大 ...

  8. MYSQL(基本篇)——一篇文章带你走进MYSQL的奇妙世界

    MYSQL(基本篇)--一篇文章带你走进MYSQL的奇妙世界 MYSQL算是我们程序员必不可少的一份求职工具了 无论在什么岗位,我们都可以看到应聘要求上所书写的"精通MYSQL等数据库及优化 ...

  9. 一篇文章带你了解热门版本控制系统——Git

    一篇文章带你了解热门版本控制系统--Git 这篇文章会介绍到关于版本控制的相关知识以及版本控制神器Git 我们可能在生活中经常会使用GitHub网页去查询一些开源的资源或者项目,GitHub就是基于G ...

随机推荐

  1. Nginx 平滑升级、Nginx的一些基础配置

    # Nginx 平滑升级 # 方案一:使用Nginx服务信号进行升级 # 1.将就版本的sbin目录下可执行nginx进行备份(mv nginx nginxold) # 2.将新版本 configur ...

  2. 项目操作案例丨西门子PLC通过网关连接ACS800变频器

    本案例控制对象为炉条机.以及蒸汽的控制以及现场数据参数的显示以及报警. PLC 选用西门子 CPU,通过 ET200 IO 模块控制现场设备并监控数据.变频器采用ABB ACS800变频器,将ABB ...

  3. 技术分析 | 浅谈在MySQL体系下SQL语句是如何在系统中执行的及可能遇到的问题

    欢迎来到 GreatSQL社区分享的MySQL技术文章,如有疑问或想学习的内容,可以在下方评论区留言,看到后会进行解答 SQL语句大家并不陌生,但某种程度上来看,我们只是知道了这条语句是什么功能,它可 ...

  4. Apache DolphinScheduler 迎来 2 位 PPMC

    经过 Apache DolphinScheduler PPMC 们的推荐和投票,我们高兴的宣布:Apache DolphinScheduler 迎来了 2 位 PPMC .他们是(github id) ...

  5. 用 Scanner 扫描CSV文件时报错:“java.util.nosuchelementexception:no line found”的解决方法

    最近用 java 对一个很大的 CSV 文件进行处理.打算用 Scanner 逐行扫描进来,结果报错 "java.util.nosuchelementexception:no line fo ...

  6. Luogu3177 [HAOI2015]树上染色 (树形DP)

    考场上打出来个\(2^n n^2 \log (n)\),还文件错误RE了... 其实这不就是个变了一点点的树形背包,状态是节点\(u\)子树的\(贡献\). //#include <iostre ...

  7. Ansible部署MySQL编译安装

    环境: 系统:centos7 x3 master:192.168.220.133 slave1:192.168.220.136 slave2:192.168.220.137 前期准备: slave1( ...

  8. 大数据Hadoop入门教程 | (一)概论

    数据是什么 数据是指对客观事件进行记录并可以鉴别的符号,是对客观事物的性质.状态以及相互关系等进行记载的物理符号或这些物理符号的组合,它是可识别的.抽象的符号. 它不仅指狭义上的数字,还可以是具有一定 ...

  9. [java]基础学习HELLOWORLD系列

    (一)手把手教你做JDK环境变量配置 步骤 1 : 首先看配置成功后的效果 点WIN键->运行(或者使用win+r) 输入cmd命令 输入java -version 注: -version是小写 ...

  10. 以太坊 layer2: optimism 源码学习(二) 提现原理

    作者:林冠宏 / 指尖下的幽灵.转载者,请: 务必标明出处. 掘金:https://juejin.im/user/1785262612681997 博客:http://www.cnblogs.com/ ...