Vue
文章目录
Purpose
Notes for Vue
分割线
v-divider
水平分割线,上下分割
v-seperator
竖直分割线,左右分割
v-if
参考: https://www.runoob.com/vue2/vue-if.html 作用: 控制可见性,是否插入对应的标签
相关指令
- v-else
- v-else-if
相似指令
- v-show
v-show
控制可见性,是否插入对应的标签
v-for
循环,重复插入标签
使用方式
v-for="site in sites"
- sites 是列表,数组
v-for="value in object"
- object 是一个对象
- 遍历对象的值,注意不是 key
- v-for="(value, key) in object"
- v-for="(value, key, index) in object"
v-for="n in 10"
- n –> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
eg:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20<div id="app"> <ol> <li v-for="site in sites"> {{ site.name }} </li> </ol> </div> <script> new Vue({ el: '#app', data: { sites: [ { name: 'Runoob' }, { name: 'Google' }, { name: 'Taobao' } ] } }) </script>
v-bind
把 html 的标签属性,绑定到 vue object 的 property
eg: <a v-bind:href="url">…</a>
- 把 <a> 元素的 href 属性绑定到 相关的 vue object 的 url 属性
设置多个值
https://www.runoob.com/vue2/vue-class-style.html
用在 class 上
eg:
| |
'active' 是要设置的 class 的名称
- vue.isActive
= true, 就会设置class'active' - 否则,不设置 class='active'
- vue.isActive
- 多个值,用逗号分开即可
用在 style 上
eg:
| |
v-on
- 用途:用于监听事件
- 作用:把 javascript 函数绑定到 vue 模板的 事件上
eg: <a v-on:click="doSomething">…</a>
- 这里 click 是事件
- 把 vue object 的方法,绑定到 click 事件
指令 Directives
以 "v-" 开头的 vue 模板标签 属性
- eg: v-if, v-bind, v-on
v-card
参考: https://blog.csdn.net/u013089490/article/details/83896439 作用: cards 卡片组件
- v-card-title
- v-card-text
v-card-action
- 按钮的容器
v-card-media
- 图片或视频的容器
v-divider
- <v-divider/>: 分割线
v-once
update template just one time, 只更新 template 模板的内容一次
v-html
vue 插入 html,
- 用法: <div v-html="vue_object_property"></div>
注:
- 存在原因: vue 在“{{ msg }}” 中插入的是纯文本,不能是 html,
- 所以,需要用 v-html 插入 html 文本
v-model
https://www.runoob.com/vue2/vue-template-syntax.html
用于表单
- 用于双向数据绑定,元素如:input, 用户输入的数据更新,
eg: <input v-model="message">
- 用户输入数据更新,对应 vue.message 也回被更新
- vue.message 也是 input 元素展示的初始内容
表单类型
input, type 不指定
input, type="checkbox"
input, type="radio"
- 多个展开的选项,但是只能选定一个
- input, type=""
select
- 下拉列表,多选一
过滤器
- 实质:过滤函数
eg:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19<div id="app"> {{ message | capitalize }} </div> <script> new Vue({ el: '#app', data: { message: 'runoob' }, filters: { capitalize: function (value) { if (!value) return '' value = value.toString() return value.charAt(0).toUpperCase() + value.slice(1) } } }) </script>使用方式
- 参数与过滤器使用 “|” 连接
创建 Vue 实例
相关参数
el
- 定位元素
data
- 属性
methods
- 方法
computed
- 计算属性
- 实际存放的是函数
filters
- 过滤器函数
watch
- 在对应属性发生改变时,自动调用关联的函数
components
组件
https://www.runoob.com/vue2/vue-component.html
类型
全局组件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Vue.component('name', {template: '...', // 和new Vue(..) 参数类似 data: {...}, methods: {...}}) // * eg Vue.component('button-counter', { template: '<button v-on:click="incrementHandler">{{ counter }}</button>', el:..., // * 注意:不需要这个属性,因为肯定使用的template 元素 data: function () { return { counter: 0 } }, methods: { incrementHandler: function () { this.counter += 1 this.$emit('increment') } }, })局部组件
在 Vue.components 下注册的 template
1 2 3 4 5 6 7new Vue( { el:.., data: {}, component: { 'child_name': child_template} })
向子组件,传参
使用 prop 属性
注意:
- 传递过来的变量,需要在 prop 属性中以列表形式声明
| |
自定义事件
https://www.runoob.com/vue2/vue-component.html
- this.$emit("event")
- this.$on("event")
Route 路由
布局
格栅 Grid
https://vuetifyjs.com/zh-Hans/components/grids/
相关功能标签
v-container/v-layout/v-flex
- vue 1.x 使用 v-layout 详细教程 https://v1.vuetifyjs.com/en/layout/grid
v-row/v-col
- vue 2.x 用法
v-col 属性
- cols: 指定跨列
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16<v-container> <v-row> <v-col cols="12" md="6" sm="12"> <v-btn block class="primary">第一个按钮</v-btn> </v-col> <v-col cols="12" md="2" sm="4" > <v-btn block class="primary">第二个按钮</v-btn> </v-col> <v-col cols="12" md="2" sm="4"> <v-btn block class="primary">第三个按钮</v-btn> </v-col> <v-col cols="12" md="2" sm="4"> <v-btn block class="primary">第四个按钮</v-btn> </v-col> </v-row> </v-container>
v-chip
属性
- color: 标签颜色
- text-color
v-tootip
属性
指定位置
- bottom, top, left, right
v-card
处理图片等
v-avatar
头像
导航栏
v-app-bar
创建导航栏
v-toolbar-title
导航栏标题
v-spacer
左右分割线
v-btn
按钮
v-icon
图标
导航抽屉
v-navigator-drawer
导航抽屉按钮
v-app-bar-nav-icon
组合实现例子
| |
列表
相关标签
- v-list
- v-list-item
- v-list-action
- v-list-content
v-list-title
1 2 3 4 5 6 7 8 9 10<v-list> <v-list-item> <v-list-item-action> <v-icon class="white--text">home</v-icon> </v-list-item-action> <v-list-item-content> <v-list-item-title class="white--text">Homepage</v-list-item-title> </v-list-item-content> </v-list-item> </v-list>
v-alert
导入
在 vue 中, 带 "@" 导入代表从根目录导入 https://www.cnblogs.com/heson/p/10517754.html
- @ 指的是 src 目录
组件名称问题
大小写问题
MainFrame 和 main-frame 等价
默认导入问题
在 components 目录下
| |
默认被自动导入,
- 使用名称 chemical_bridges
- 名称格式:parentFolderName_componentName
Vuex
mapState, mapActions, mapMutations
文章作者
上次更新 2023-02-10 (97c415e)