当前位置: 首页 > news >正文

vue查缺补漏

之前学习过vue基础,在工作上使用的时候也没有什么问题。最近在看30分钟学会Vue之核心语法,发现有一些不常用的、但挺重要的都快忘掉了,在此补漏一下。

请添加图片描述

搭建演示环境

创建index.html 导入 vue.min.js文件

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<div id="app"><p>{{ msg }}</p>
</div>
<script src="./vue.min.js"></script>
<script>const vm = new Vue({el: '#app',data() {return {msg: 'Hello World',}}})
</script>
</body>
</html>

1. 内容指令

    <p v-text="msg">1111</p><p v-html="msg">1111</p>

不显示1111,显示msg内容 v-html 解析msg中的html标签

2. console.log 打印

console.log(newVal,oldVal);

console打印可以直接进行参数拼接,并不需要+进行连接

3. for 遍历对象打印属性

   <p v-for="(item,key,index) in 5">item:{{ item }},key:{{ key }},index:{{ index }}</p><p v-for="(item,key,index) in obj">item:{{ item }},key:{{ key }},index:{{ index }}</p>obj: {name: 'gggg', age: 1111}
item:1,key:0,index:item:2,key:1,index:item:3,key:2,index:item:4,key:3,index:item:5,key:4,index:item:gggg,key:name,index:0item:1111,key:age,index:1

4. 放到标签上进行文本提示

    <p title="这是内容">{{ msg }}</p>

请添加图片描述

5. input自动去空格

        <input type="text" v-model.trim="inputVal"/> 

6. style、class绑定

在uniapp开发的时候,也会使用 当时云里雾里的。

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<div id="app"><!--  前面两种指定style中定义的内容,必须使用'字符串',用,分割--><!-- key:value  key 自动转为字符串 --><div v-bind:class="{ textColorCls: textColorFlag,bgColorCls: bgColorFlag}">111111</div><!-- 直接使用字符串,内嵌的对象,或者三元表达式 --><div v-bind:class="[ 'textColorCls', {bgColorCls: bgColorFlag},textSizeFlag? 'textSizeCls' : '']">111111</div><!-- 使用data中定义的 包含style的集合 --><div v-bind:class="textColorClassObj">2222</div><!-----------------------------不支持 {textSizeClassObj:  textSizeFlag}, ---------------------------------------><div v-bind:class="[textColorClassObj,  bgColorFlag ? bgColorClassObj:'']">2222</div><div v-bind:style="{ color: textColor, fontSize: fontSize + 'px' }">333333</div><div v-bind:style="textColorStyleObj">44444</div><!-----------------------------不支持{textSizeStyleObj:true} ---------------------------------------><div v-bind:style="[{ background: bgColor}, textColorFlag ? textColorStyleObj:'']">44444</div></div>
<script src="./vue.min.js"></script><style>.textColorCls {color: red;}.bgColorCls {background: #ff0;}.textSizeCls {font-size: 30px;}
</style><script>const vm = new Vue({el: '#app',data() {return {textColor: 'red',bgColor: 'yellow',fontSize: 30,bgColorFlag: true,textSizeFlag: true,textColorFlag: true,//这两个不能混用textColorClassObj: {textColorCls: true //只能指定class,并且必须写'显示'逻辑.},bgColorClassObj: {bgColorCls: true //只能指定class,并且必须写'显示'逻辑.},textSizeClassObj: {textSizeCls: true //只能指定class,并且必须写'显示'逻辑.},textColorStyleObj: {color: 'red',},textSizeStyleObj: {'font-size': 30 + 'px',},}},})
</script>
</body>
</html>

http://www.mrgr.cn/news/54422.html

相关文章:

  • 接口测试(三)jmeter——连接mysql数据库
  • 基于微博评论的自然语言处理情感分析
  • 电影评论网站开发:Spring Boot技术指南
  • 外贸企业如何应对网络卡顿与网页打不开的问题
  • java计算两个日期之间相差几天(小时、天)小时计算
  • owasp top 10漏洞原理与防御技术(原理和对应防御技术)
  • 不同jdk版本中的接口规范
  • Python生成随机密码脚本
  • curl,nc和telnet的用法以及其他常用工具(nc代理与重定向)
  • 用 CSS 和 JS 打造简约又不失亮点的客户评价展示
  • 【Python】基础语法
  • 【Linux】main函数的参数列表从何而来?
  • 基于SpringBoot基于微信的借书驿站小程序【附源码】
  • 嘉立创EDA个人学习笔记2(绘制51单片机核心板)
  • EDA系统的性能
  • ChatGLM-6B中英双语对话大模型Windows本地部署实战
  • Vulhub Basic Pentesting: 2 Target Machines
  • 如何高效练习键盘盲打?这些在线网站帮你提高打字速度
  • Node.js 版本管理工具 n
  • 值传递和引用传递
  • spring boot实现不停机更新
  • 【Spring篇】Spring中的Bean管理
  • Reflection 70B乌龙事件始末:揭开“最强大模型”背后的真相
  • 工信部绿色工厂、绿色设计产品、绿色供应链企业、绿色园区名单(2017-2022年)
  • 07 P1088 [NOIP2004 普及组] 火星人
  • 脉冲扩散模型