layui/example/docs/zh-CN/components/tab.md

251 lines
4.7 KiB
Markdown
Raw Normal View History

::: anchor
:::
2021-10-26 01:13:23 +08:00
::: title 基础使用
2021-10-19 22:28:44 +08:00
:::
2021-10-05 19:04:06 +08:00
::: demo
<template>
<lay-tab v-model="current1">
2021-10-08 19:57:03 +08:00
<lay-tab-item title="选项一" id="1"><div style="padding:20px">选项一</div></lay-tab-item>
<lay-tab-item title="选项二" id="2"><div style="padding:20px">选项二</div></lay-tab-item>
</lay-tab>
2021-10-08 17:32:05 +08:00
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const current1 = ref("1")
2021-10-08 19:57:03 +08:00
2021-10-08 17:32:05 +08:00
return {
current1
2021-10-08 17:32:05 +08:00
}
}
}
</script>
:::
2021-10-26 01:13:23 +08:00
::: title 简约模式
2021-10-19 22:28:44 +08:00
:::
2021-10-08 17:32:05 +08:00
::: demo
<template>
2021-10-08 19:57:03 +08:00
<lay-tab type="brief" v-model="current2">
<lay-tab-item title="选项一" id="1"><div style="padding:20px">选项一</div></lay-tab-item>
<lay-tab-item title="选项二" id="2"><div style="padding:20px">选项二</div></lay-tab-item>
</lay-tab>
2021-10-08 17:32:05 +08:00
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
2021-10-08 19:57:03 +08:00
const current2 = ref("1")
2021-10-08 17:32:05 +08:00
return {
2021-10-08 19:57:03 +08:00
current2
2021-10-08 17:32:05 +08:00
}
}
}
</script>
:::
2021-10-26 01:13:23 +08:00
::: title 卡片模式
2021-10-19 22:28:44 +08:00
:::
2021-10-08 17:32:05 +08:00
::: demo
<template>
2021-10-08 19:57:03 +08:00
<lay-tab type="card" v-model="current3">
<lay-tab-item title="选项一" id="1"><div style="padding:20px">选项一</div></lay-tab-item>
<lay-tab-item title="选项二" id="2"><div style="padding:20px">选项二</div></lay-tab-item>
</lay-tab>
2021-10-05 19:04:06 +08:00
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
2021-10-08 19:57:03 +08:00
const current3 = ref("1")
2021-10-05 19:04:06 +08:00
return {
2021-10-08 19:57:03 +08:00
current3
2021-10-05 19:04:06 +08:00
}
}
}
</script>
2021-10-09 10:41:52 +08:00
:::
2021-10-26 01:13:23 +08:00
::: title 允许关闭
2021-10-19 22:28:44 +08:00
:::
::: demo
<template>
<lay-tab type="card" v-model="current4" :allow-close="allowClose" @change="change" @close="close">
<lay-tab-item title="选项一" id="1"><div style="padding:20px">选项一</div></lay-tab-item>
<lay-tab-item title="选项二" id="2"><div style="padding:20px">选项二</div></lay-tab-item>
2021-12-10 08:01:48 +08:00
<lay-tab-item title="选项三" id="3"><div style="padding:20px">选项三</div></lay-tab-item>
</lay-tab>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const current4 = ref("1")
const allowClose = ref(true)
const change = function(id){
console.log("当前值:" +id)
}
const close = function(id){
2021-12-10 08:01:48 +08:00
console.log("当前关闭:" + id)
}
return {
current4,
allowClose,
change,
close
}
}
}
</script>
:::
2021-12-10 08:01:48 +08:00
::: title 控制是否关闭
:::
::: demo
<template>
<lay-tab type="card" v-model="current5" allow-close @change="change5" @close="close5" :beforeClose="beforeClose">
<lay-tab-item title="选项一" id="1"><div style="padding:20px">选项一</div></lay-tab-item>
<lay-tab-item title="选项二" id="2"><div style="padding:20px">选项二</div></lay-tab-item>
<lay-tab-item title="选项三" id="3"><div style="padding:20px">选项三</div></lay-tab-item>
<lay-tab-item title="选项四" id="4"><div style="padding:20px">选项四</div></lay-tab-item>
<lay-tab-item title="选项五" id="5"><div style="padding:20px">选项五</div></lay-tab-item>
</lay-tab>
<div style="color:#ff5722;">id为单数的可以关闭</div>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const current5 = ref("1")
const change5 = function(id){
console.log("当前值:" +id)
}
const beforeClose = function(id){
return parseInt(id) % 2 === 1;
}
const close5 = function(id){
console.log("当前关闭:" + id)
}
return {
current5,
change5,
beforeClose
close5
}
}
}
</script>
:::
2021-10-26 01:13:23 +08:00
::: title 嵌套循环
2021-10-19 22:28:44 +08:00
:::
::: demo
<template>
2021-12-10 08:01:48 +08:00
<lay-tab type="card" v-model="current6" @change="change6">
<lay-tab-item v-for="a in arr" :key="a" :title="a.title" :id="a.id">
2021-12-10 08:01:48 +08:00
内容{{a.id}}
</lay-tab-item>
</lay-tab>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
2021-12-10 08:01:48 +08:00
const current6 = ref('1')
const change6 = function(id){
2021-10-19 22:28:44 +08:00
alert(id)
}
2021-10-19 22:28:44 +08:00
const arr = ref([
{id:'1', title:'选项一'},
{id:'2', title:'选项二'}
2021-10-19 22:28:44 +08:00
])
arr.value.push({id:'3', title:'选项三'})
return {
2021-12-10 08:01:48 +08:00
current6,
arr
}
}
}
</script>
:::
::: title 选项卡属性
:::
2021-10-12 18:00:09 +08:00
2021-11-07 15:55:08 +08:00
::: table
| 属性 | 描述 | 可选值 |
| ----------- | -------- | -------------- |
| v-model | 当前激活 | -- |
| type | 主题样式 | -- |
| allow-close | 允许关闭 | `true` `false` |
2021-12-10 08:01:48 +08:00
| before-close | `Function`关闭之前的回调钩子函数 | 参数(`id`), `return false` 表示不进行关闭 |
| before-leave | `Function`切换标签之前的回调钩子函数 | 参数(`id`), `return false` 表示不进行切换 |
2021-11-07 15:55:08 +08:00
:::
::: title 选项卡事件
:::
2021-11-07 15:55:08 +08:00
::: table
| 事件 | 描述 | 参数 |
| ------ | -------- | ---- |
2021-12-10 08:01:48 +08:00
| change | 选中切换 | id |
| close | 关闭事件 | id |
2021-11-07 15:55:08 +08:00
2021-11-07 15:56:24 +08:00
:::
2021-12-16 17:57:59 +08:00
::: comment
:::