当前位置:网站首页>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>
边栏推荐
- 【Autosar RTM】
- Connect the Snowflake of CKAN tutorial CKAN to release to open data portal
- 优秀论文以及思路分析02
- 精心整理16条MySQL使用规范,减少80%问题,推荐分享给团队
- Swift中的类型相关内容
- Teach you to locate online MySQL slow query problem hand by hand, package teaching package meeting
- js基础知识整理之 —— Date和定时器
- 最近公共祖先(LCA)学习笔记 | P3379 【模板】最近公共祖先(LCA)题解
- scala 集合通用方法
- 一文读懂 Web 3.0 应用架构
猜你喜欢
精心整理16条MySQL使用规范,减少80%问题,推荐分享给团队
Servlet——请求(request)与响应(response)
谷歌 Chrome 浏览器 104 正式版发布:加快网页加载,蓝牙 API 改进
alibaba数据同步组件canal的实践整理
语音合成模型小抄(1)
Teach you to locate online MySQL slow query problem hand by hand, package teaching package meeting
即席查询—— Kylin使用
剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
Let's talk about the charm of code language
Test | ali internship 90 days in life: from the perspective of interns, talk about personal growth
随机推荐
4、Citrix MCS云桌面无法安装todesk等软件
2022第十一届财经峰会:优炫软件斩获双项大奖
# DWD层及DIM层构建## ,220801 ,
LVM与磁盘配额原理及配置
同一份数据,Redis为什么要存两次?
用了TCP协议,就一定不会丢包吗?
2022 Shandong International Youth Eye Health Industry Exhibition, Vision Health Exhibition, Optometry Exhibition
嵌入式分享合集26
6、Powershell命令配置Citrix PVS云桌面桌面注销不关机
升级版的冒泡排序:鸡尾酒排序(快乐小时排序)
NLP常用Backbone模型小抄(1)
@GetMapping、@PostMapping、@PutMapping、@DeleteMapping的区别
Jenkins汉化设置
Auto.js 特殊定位控件方法 不能在ui线程执行阻塞操作,请使用setTimeout代替
js基础知识整理之 —— 字符串
js基础知识整理之 —— 闭包
airflow db init 报错
高数---二重积分
漫画:怎么证明sleep不释放锁,而wait释放锁?
Rasa 3.x 学习系列- Rasa - Issues 4792 socket debug logs clog up debug feed学习笔记