当前位置:网站首页>vue3的keepAlive缓存组件
vue3的keepAlive缓存组件
2022-08-02 23:44:00 【@小朱呀路】


新建login.vue
<template>
<div>login 此界面的输入框的东西切换回来就没了
<input type="text">
<input type="text">
<button @click="submit">登陆</button>
</div>
</template>
<script setup lang="ts">
</script>
<script >
export default{
name:'login'
}
</script>
<style scoped>
</style>
新建insert.vue
<template>
<div>insert 无论切换都会保留input的内容
<input type="text" v-model="data.reform.text">
<input type="text" v-model="data.reform.password">
<input type="text" v-model="data.reform.code">
<button @click="submit">注册</button>
</div>
</template>
<script setup lang="ts">
import {
reactive,onActivated} from 'vue'
type refo={
reform:{
text:string,
password:string,
code:string
}
}
let data=reactive<refo>({
reform:{
text:"",password:'',code:''}
})
onActivated(()=>{
data.reform.code=''
})
</script>
<style scoped>
</style>
父组件引入
<template>
<div class="content">
<button @click="slectadd">切换</button>
<keep-alive :exclude="['login']">
<login v-if="flag"/>
<insert v-else/>
</keep-alive>
</div>
</template>
<script setup lang="ts">
import {
reactive ,markRaw,ref} from 'vue'
import login from '../../components/login/index.vue'
import insert from '../../components/insert/index.vue'
const flag=ref(true);
const slectadd=()=>{
flag.value=!flag.value
}
</script>
<style scoped lang="less">
.bg-red{
background: red;
}
.content{
flex: 1;
display: flex;
// height: 100vh;
margin: 20px;
border-bottom: 1px solid #ccc;
overflow: auto;
&-items{
padding:20px;border-bottom: 1px solid #ffffff;
}
.tab{
height: 50px;
border:1px solid red;
}
component{
height: 30px;;
}
}
</style>
边栏推荐
猜你喜欢

CAS:1445723-73-8,DSPE-PEG-NHS,磷脂-聚乙二醇-活性酯两亲性脂质PEG共轭物

精心整理16条MySQL使用规范,减少80%问题,推荐分享给团队
Teach you to locate online MySQL slow query problem hand by hand, package teaching package meeting

「PHP基础知识」隐式数据类型

Auto.js 特殊定位控件方法 不能在ui线程执行阻塞操作,请使用setTimeout代替

js基础知识整理之 —— 获取元素和命名规范

Swift中的类型相关内容

我为什么又能面试一次就拿到offer

CIO修炼手册:成功晋升CIO的七个秘诀

Database auditing - an essential part of network security
随机推荐
Teach you to locate online MySQL slow query problem hand by hand, package teaching package meeting
程序员的七夕浪漫时刻
random.nextint()详解
Cholesterol-PEG-Acid,胆固醇-聚乙二醇-羧基保持在干燥、低温环境下
心电记录电路设计(框图/波形以及信号放大器的选择)
CIO修炼手册:成功晋升CIO的七个秘诀
fifa将采用半自动越位技术计算进球
@GetMapping、@PostMapping、@PutMapping、@DeleteMapping的区别
CKAN教程之将 Snowflake 连接到 CKAN 以发布到开放数据门户
升级版的冒泡排序:鸡尾酒排序(快乐小时排序)
Auto.js 特殊定位控件方法 不能在ui线程执行阻塞操作,请使用setTimeout代替
HVV红队 | 渗透测试思路整理
机器学习-特征映射方法
有奖提问|《新程序员》专访“Apache之父”Brian Behlendorf
浅谈I2C知识
VMware workstation program starts slowly
js基础知识整理之 —— 变量和数据类型
程序员常说的“左手锟斤拷,右手烫烫烫”是怎么回事?
华为设备配置BFD与接口联动(触发与BFD联动的接口物理状态变为Down)
几种常见的跨域解决方法