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

javaee是做网站的?指数基金有哪些

javaee是做网站的?,指数基金有哪些,海报设计app,java主要就是做网站吗shallowRef和shallowReactive shallowRef 作用&#xff1a;创建一个响应式数据&#xff0c;但只对顶层属性进行响应式处理 用法 let myVar shallowRef(initialValue)特点&#xff1a;只跟踪引用值变化&#xff0c;不关心值内部的属性变化 案例 <template><div c…

shallowRef和shallowReactive

shallowRef

  1. 作用:创建一个响应式数据,但只对顶层属性进行响应式处理

  2. 用法

    let myVar = shallowRef(initialValue)
    
  3. 特点:只跟踪引用值变化,不关心值内部的属性变化

案例

<template><div class="app"><h2>求和为:{{ sum }}</h2><h2>名字为:{{ person.name }}</h2><h2>年龄为:{{ person.age }}</h2><h2>汽车为:{{ car }}</h2><button @click="changeSum">sum+1</button><button @click="changeName">修改名字</button><button @click="changeAge">修改年龄</button><button @click="changePerson">修改整个人</button><span>|||||</span><button @click="changeBrand">修改品牌</button><button @click="changeColor">修改颜色</button><button @click="changeEngine">修改发动机</button><!-- <button @click="changeCar">修改整个车</button> --></div>
</template><script setup lang="ts" name="App">import { ref,reactive,shallowRef,shallowReactive } from 'vue'let sum = shallowRef(0)let person = shallowRef({name: '小黑',age:2})let car = shallowReactive({brand: '特斯拉',options: {color: '黑色',engine:'v8'}})function changeSum (){sum.value += 1;}// 不会改变function changeName (){person.value.name = '大狗';}function changeAge (){person.value.age = 5;}//只能改变第一层function changePerson (){person.value = {name:'乐乐',age:3}}/* ********** */function changeBrand () {car.brand = '宝马'}function changeColor () {car.options.color = '红色'}function changeEngine () {car.options.engine = 'v12'}// function changeCar () {// 	Object.assign(car,{})// }
</script><style scoped>.app{background-color: #ddd;border-radius: 10px;box-shadow: 0 0 10px;padding: 10px;}button{margin:0 5px;}
</style>

总结

通过使用shallowRef()和shallowReactive()来绕开深度响应。浅层式API创建的状态只在其顶层是响应式的,对所有深层的对象不会做任何处理,避免了对每一个内部属性做响应式所带来的性能成本,这使得属性的访问控制变得更快、可提升性能。

readonly与shallowReadonly

readonly

  1. 作用:用于创建一个对象的深只读副本

  2. 用法

    <template><div class="app"><h2>当前求和为:{{ sum }}</h2><h2>当前sum2求和为:{{ sum2 }}</h2><h2>当前car1为:{{ car }}</h2><h2>当前car2为:{{ car2 }}</h2><button @click="changeSum">点我sum+1</button><button @click="changeSum2">点我sum2+1</button></div>
    </template><script setup lang="ts" name="App">import { ref, readonly, reactive,shallowReadonly } from 'vue';let sum = ref(0)let sum2 = readonly(sum)function changeSum() {sum.value += 1}function changeSum2() {sum2.value += 1  //sum2不可修改}
    </script><style scoped>.app{background-color: #ddd;border-radius: 10px;box-shadow: 0 0 10px;padding: 10px;}button{margin:0 5px;}
    </style>
    
  3. 特点:

    • 对象的所有嵌套属性变成只读
    • 任何尝试修改这个对象的操作都会被组织(在开发模式下,还会再控制台中发出警告)
  4. 应用场景:

    • 创建不可变的状态快照
    • 保护全局状态或配置不被修改

shallowReadonly

  1. 作用:与readonly类似,但只作用于对象的顶层属性,其他地方仍然可以修改

  2. 用法

    <template><div class="app"><h2>当前car1为:{{ car }}</h2><h2>当前car2为:{{ car2 }}</h2><button @click="changeBrand1">修改car1品牌</button><button @click="changeColor1">修改car1颜色</button><button @click="changePrice1">修改car1价格</button><button @click="changeBrand2">修改car2品牌</button><button @click="changeColor2">修改car2颜色</button><button @click="changePrice2">修改car2价格</button></div>
    </template><script setup lang="ts" name="App">import { reactive,shallowReadonly } from 'vue';let car = reactive({brand:'奔驰',options: {color:'黑色',price:100}})let car2 = shallowReadonly(car)function changeBrand1() {car.brand = '宝马'}function changeColor1() {car.options.color = '红色'}function changePrice1() {car.options.price += 10}function changeBrand2() {car2.brand = '宝马'}function changeColor2() {car2.options.color = '红色'}function changePrice2() {car2.options.price += 10}
    </script><style scoped>.app{background-color: #ddd;border-radius: 10px;box-shadow: 0 0 10px;padding: 10px;}button{margin:0 5px;}
    </style>
    

toRaw与markrow

toRaw

  1. 作用:用于获取一个响应式对象的原始对象,toRaw返回的对象不再是响应式,不会触发视图更新。

    • 何时使用

      在需要将响应式对象传递给非Vue的库或外部系统时,使用toRaw可以确保他们收到的是普通对象

  2. 用法:使用toRaw之后 年龄不再改变

    <template><div class="app"><h2>姓名:{{ person.name }}</h2><h2>年龄:{{ person2.age }}</h2><button @click="person.age += 1">修改年龄</button></div>
    </template><script setup lang="ts" name="App">
    import { reactive,toRaw } from 'vue';let person = reactive({name: '小黑',age:2
    })
    let person2 = toRaw(person)console.log('响应式数据', person)
    console.log('原始数据',person2)
    </script><style scoped>.app{background-color: #ddd;border-radius: 10px;box-shadow: 0 0 10px;padding: 10px;}button{margin:0 5px;}
    </style>
    

markRaw

  1. 作用:标记一个对象,使其永远都不会变成响应式

    • 何时使用

      使用第三方库的时候,防止错误把第三库对象变成响应式对象,就可以使用markRaw

  2. 用法

    <template><div class="app"><h2>汽车:{{ car2 }}</h2><button @click="car2.price += 10">修改价格</button></div>
    </template><script setup lang="ts" name="App">
    import { reactive,toRaw,markRaw } from 'vue';/* markRaw */
    //添加markRaw 28行就失去作用,无法改变成响应式
    let car = markRaw({ brand: '奔驰', price: 100 })
    let car2 = reactive(car)console.log(car);
    console.log(car2);</script><style scoped>.app{background-color: #ddd;border-radius: 10px;box-shadow: 0 0 10px;padding: 10px;}button{margin:0 5px;}
    </style>
    

customRef的使用

作用:创建一个自定义的ref,并对其依赖项跟踪和更新触发进行逻辑控制

实现防抖效果(useSumRef.ts)

<template><div class="app"><h2>{{ msg }}</h2><input type="text" v-model="msg"></div>
</template><script setup lang="ts" name="App">import { ref,customRef } from 'vue'//使用vue提供的默认ref定义响应式数据,数据一变,页面视图也更新// let msg = ref('你好')//使用vue提供的customRef定义响应式数据let initValue = '你好'let timer:number//track(跟踪)、trigger(触发) 不加上页面效果不会改变let msg = customRef((track,trigger) => {return {//get何时调用?——msg被读取时get() { track() //告诉vue数据很重要,需要对msg进行持续关注,一旦msg变化就去更新return initValue},//set何时调用?——msg被修改时set(value) {clearTimeout(timer)timer = setTimeout(() => {// console.log('set',value);initValue = valuetrigger() //通知vue数据变化了}, 1000);}}})
</script><style scoped>.app{background-color: #ddd;border-radius: 10px;box-shadow: 0 0 10px;padding: 10px;}button{margin:0 5px;}
</style>

采用hooks封装

定义hooks——useMsgRef.ts

import { customRef } from 'vue';export default function (initValue: string, delay: number) {//使用vue提供的customRef定义响应式数据// let initValue = '你好'let timer: number//track(跟踪)、trigger(触发) 不加上页面效果不会改变let msg = customRef((track, trigger) => {return {//get何时调用?——msg被读取时get() {track() //告诉vue数据很重要,需要对msg进行持续关注,一旦msg变化就去更新return initValue},//set何时调用?——msg被修改时set(value) {clearTimeout(timer)timer = setTimeout(() => {// console.log('set',value);initValue = valuetrigger() //通知vue数据变化了}, delay); //延迟时间不要写死}}})//hooks必须要有返回值return { msg }
}

App.vue

<template><div class="app"><h2>{{ msg }}</h2><input type="text" v-model="msg"></div>
</template><script setup lang="ts" name="App">import useMsgRef from './useMsgRef';//使用useMsgRef来定义一个响应式数据且有延迟效果let { msg } = useMsgRef('小黑', 2000)</script><style scoped>.app{background-color: #ddd;border-radius: 10px;box-shadow: 0 0 10px;padding: 10px;}button{margin:0 5px;}
</style>

Teleport

定义:Teleport是一种能够将我们的组件html结构移动到指定位置的技术

App.vue

<template><div class="outer"><h2>我是App组件</h2><img src="https://img.zcool.cn/community/014b275d0a1c95a801213ec257bb95.jpg@2o.jpg" alt=""><br><Modal/></div>
</template><script setup lang="ts" name="App">import Modal from './Modal.vue';
</script><style  scoped>
.outer{background-color: #ddd;border-radius: 10px;padding:5px;box-shadow: 0 0 10px;width: 500px;height: 500px;/* 添加滤镜后,模块定位不再参考视口,参考的是父容器了 */filter:saturate(150%);
}
img{height: 180px;object-fit: cover;
}
</style>

modal.vue

<template><button @click="isshow = true">展示弹窗</button><!-- teleport解决添加滤镜后fix定位问题 --><teleport to='body'><div class="modal" v-show="isshow"><h2>我是弹窗标题</h2><p>我是弹窗内容</p><button @click="isshow = false">关闭弹窗</button></div></teleport>
</template><script setup lang="ts" name="Modal">
import { ref } from 'vue'
let isshow = ref(false)
</script><style  scoped>
.modal{width: 200px;height: 150px;background-color: skyblue;border-radius: 10px;padding: 5px;box-shadow: 0 0 5px;text-align: center;position:fixed;left:50%;top: 20px;margin-left: -100px;
}
</style>

Suspense

  • 等待异步组件时渲染一些额外内容,让应用有更好的用户体验
  • 使用步骤:
    • 异步引入组件
    • 使用Suspense包裹组件,并配置好default和fallback

App.vue

<template><div class="app"><h2>我是App组件</h2><!-- 解决异步事件,如果不加下面,那么Child组件不显示 --><Suspense><template v-slot:default><Child/></template></Suspense></div>
</template><script setup lang="ts" name="App">import { Suspense } from 'vue'import Child from './Child.vue'
</script><style scoped>
.app{border-color: #ddd;border-radius:10px;padding:10px;box-shadow: 0 0 10px;
}
</style>

Child.vue

<template><div class="child"><h2>我是Child组件</h2><h3>当前sum求和为:{{ sum }}</h3></div>
</template><script setup lang="ts">
import { ref } from 'vue'
import axios from 'axios'let sum = ref(0)
let xxx = await axios.get('https://api.uomg.com/api/rand.qinghua?format=json')
console.log(xxx);
//如果要看到数据,可以解构 xxx 替换成 {data{content}} log直接打印content即可</script><style scoped>
.child{background-color: skyblue;border-radius:10px;padding:10px;box-shadow: 0 0 10px;
}
</style>

全局API转移到应用对象

  • app.component

App.vue

<template><div class="app"><h2>我是App组件</h2><Hello/><Child/></div>
</template><script setup lang="ts" name="App">import Child from './Child.vue'
</script><style scoped>
.app{border-color: #ddd;border-radius:10px;padding:10px;box-shadow: 0 0 10px;
}
</style>

Child.vue

<template><div class="child"><h2>我是Child组件</h2><h3>当前sum求和为:{{ sum }}</h3><Hello/></div>
</template><script setup lang="ts">
import { ref } from 'vue'let sum = ref(0)</script><style scoped>
.child{background-color: skyblue;border-radius:10px;padding:10px;box-shadow: 0 0 10px;
}
</style>

Hello.vue

<template><h2 style="color:red">你好</h2>
</template><script setup lang="ts" ></script><style scoped></style>

main.ts

import { createApp } from 'vue'
import App from './App.vue'
import Hello from './Hello.vue'// 创建应用
const app = createApp(App)app.component('Hello', Hello)// 挂载应用
app.mount('#app')
  • app.config

main.ts

app.config.globalProperties 添加 那么全局都可以使用

import { createApp } from 'vue'
import App from './App.vue'
import Hello from './Hello.vue'// 创建应用
const app = createApp(App)app.component('Hello', Hello)
app.config.globalProperties.x = 99//这样下面x就不会爆红
declare module 'vue' {interface ComponentCustomProperties {// $http: typeof axios// $translate: (key: string) => stringx: number}
}// 挂载应用
app.mount('#app')

比如:Child.vue 页面就会呈现 我是Child组件99 这里x会爆红 在main.ts添加定义部分

<template><div class="child"><h3>当前sum求和为:{{ sum }}</h3><Hello/></div>
</template><script setup lang="ts">
import { ref } from 'vue'let sum = ref(0)</script><style scoped>
.child{background-color: skyblue;border-radius:10px;padding:10px;box-shadow: 0 0 10px;
}
</style>
  • app.directive

main.ts

import { createApp } from 'vue'
import App from './App.vue'
import Hello from './Hello.vue'// 创建应用
const app = createApp(App)app.directive('beauty', (element, { value }) => {element.innerText += valueelement.style.color = 'green'element.style.backgroundColor = 'yellow'
})// 挂载应用
app.mount('#app')

比如:Child.vue 页面就会呈现 不高兴0——黄色背景,绿色文字

<template><div class="child"><h2>我是Child组件{{ x }}</h2><h3>当前sum求和为:{{ sum }}</h3><h4 v-beauty="sum">不高兴</h4><Hello/></div>
</template><script setup lang="ts">
import { ref } from 'vue'let sum = ref(0)</script><style scoped>
.child{background-color: skyblue;border-radius:10px;padding:10px;box-shadow: 0 0 10px;
}
</style>
  • app.mount

main.ts

import { createApp } from 'vue'
import App from './App.vue'
import Hello from './Hello.vue'
import type axios from 'axios'// 创建应用
const app = createApp(App)// 挂载应用
app.mount('#app')
  • app.unmount

main.ts 2秒钟之后 app消失在页面上

import { createApp } from 'vue'
import App from './App.vue'
import Hello from './Hello.vue'
import type axios from 'axios'// 创建应用
const app = createApp(App)// 挂载应用
app.mount('#app')setTimeout(() => {app.unmount()
}, 2000);
  • app.use

见router那一节 安装插件

//使用路由器
app.use(router)

Vue3的非兼容性改变

Vue2和Vue3区别

看vue官网:Breaking Changes | Vue 3 Migration Guide (vuejs.org)

  • 过渡类名v-enter 修改为 v-enter-from、过渡类名 v-leave 修改为 v-leave-from 。
  • keyCode 作为 v-on 修饰符的支持。
  • v-model 指令在组件上的使用已经被重新设计,替换掉了v-bind.sync。
  • v-if 和 v-for 在同一个元素身上使用时的优先级发生了变化。
  • 移除了 Son、 Soff 和 Sonce 实例方法。
  • 移除了过滤器 filter。
  • 移除了 $children 实例 propert。
http://www.yidumall.com/news/9240.html

相关文章:

  • 商业网站建设案例笔记免费优化
  • 为什么用wp做网站优化方案
  • b2c电子商务网站建设方案最让顾客心动的促销活动
  • 建材做网站好吗站长工具查询域名
  • app商城开发价格外贸seo推广招聘
  • 免费的行情网站推荐下载安装化妆品网络营销策划方案
  • 重庆市建设施工程信息网宁波搜索引擎优化seo
  • 石家庄seo网站建设网络营销推广公司名称
  • 哈密网站建设seo排名方案
  • 怎样做网站设计要交税吗怎么搭建一个网站
  • 网站建设论文3000字seo站长工具查询
  • 重庆网站建设选夹夹虫seo优化上首页
  • 厦门做网站优化多少钱百度官网推广
  • 刚做的网站 为啥搜不到南京谷歌seo
  • 常州市新北区建设局网站厦门seo优化多少钱
  • 龙岩网站设计网站推广什么意思
  • 中国空间站天宫课堂专业全网优化
  • 装饰公司网站设计share群组链接分享
  • 帮人做网站一定要先收费企业网站设计思路
  • 建国内外网站有什么区别seo的工作内容
  • 怎样加入装修接单网站windows7系统优化工具
  • c 教学网站开发北京搜索引擎优化管理专员
  • 百度做的网站后台怎么建设苏州seo排名优化课程
  • 烟台优化网站搜索引擎推广方式有哪些
  • 程序员做赌博类网站枣庄网站seo
  • 企业网站怎么做的好看营销比较成功的品牌
  • 我国档案网站建设研究论文广告营销案例100例
  • 武汉做鸭兼职网站湖南靠谱seo优化报价
  • 优惠券网站做代理怎么样登录百度app
  • wordpress代替系统嘉兴seo