mirror of
https://github.com/luzhisheng/js_reverse.git
synced 2025-04-19 18:24:51 +08:00
vue学习
This commit is contained in:
parent
0f623c5fb6
commit
a3225b9989
@ -42,10 +42,12 @@
|
|||||||
padding: 20px;
|
padding: 20px;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-evenly;
|
justify-content: space-evenly;
|
||||||
}
|
}
|
||||||
|
|
||||||
img, video {
|
img, video {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts" name="Game">
|
<script setup lang="ts" name="Game">
|
||||||
import {reactive} from 'vue'
|
import {reactive} from 'vue'
|
||||||
|
|
||||||
let games = reactive([
|
let games = reactive([
|
||||||
{id: 'asgytdfats01', name: '英雄联盟'},
|
{id: 'asgytdfats01', name: '英雄联盟'},
|
||||||
{id: 'asgytdfats02', name: '王者农药'},
|
{id: 'asgytdfats02', name: '王者农药'},
|
||||||
@ -23,6 +24,7 @@
|
|||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
box-shadow: 0 0 10px;
|
box-shadow: 0 0 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
background-color: orange;
|
background-color: orange;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
<h3>父组件</h3>
|
<h3>父组件</h3>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<Category title="热门游戏列表">
|
<Category title="热门游戏列表">
|
||||||
|
<!-- 根据子组建的 <slot>默认内容</slot> 显示内容-->
|
||||||
<ul>
|
<ul>
|
||||||
<li v-for="g in games" :key="g.id">{{ g.name }}</li>
|
<li v-for="g in games" :key="g.id">{{ g.name }}</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
29
学习VUE/hello_vue3/src/utils/emitter.ts
Normal file
29
学习VUE/hello_vue3/src/utils/emitter.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// 引入mitt
|
||||||
|
import mitt from 'mitt'
|
||||||
|
|
||||||
|
// 调用mitt得到emitter,emitter能:绑定事件、触发事件
|
||||||
|
const emitter = mitt()
|
||||||
|
|
||||||
|
/* // 绑定事件
|
||||||
|
emitter.on('test1',()=>{
|
||||||
|
console.log('test1被调用了')
|
||||||
|
})
|
||||||
|
emitter.on('test2',()=>{
|
||||||
|
console.log('test2被调用了')
|
||||||
|
})
|
||||||
|
|
||||||
|
// 触发事件
|
||||||
|
setInterval(() => {
|
||||||
|
emitter.emit('test1')
|
||||||
|
emitter.emit('test2')
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
// emitter.off('test1')
|
||||||
|
// emitter.off('test2')
|
||||||
|
emitter.all.clear()
|
||||||
|
}, 3000); */
|
||||||
|
|
||||||
|
|
||||||
|
// 暴露emitter
|
||||||
|
export default emitter
|
27
学习VUE/hello_vue3/笔记/shallowRef与shallowReactive.vue
Normal file
27
学习VUE/hello_vue3/笔记/shallowRef与shallowReactive.vue
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { shallowRef } from 'vue';
|
||||||
|
|
||||||
|
const user = shallowRef({ name: 'Alice', age: 30 });
|
||||||
|
|
||||||
|
// 修改 user 本身会触发更新
|
||||||
|
user.value = { name: 'Bob', age: 25 }; // 响应式触发
|
||||||
|
|
||||||
|
// 修改 user.value 的属性不会触发更新
|
||||||
|
user.value.name = 'Charlie'; // 不会触发响应式更新
|
||||||
|
|
||||||
|
|
||||||
|
import { shallowReactive } from 'vue';
|
||||||
|
|
||||||
|
const user = shallowReactive({
|
||||||
|
name: 'Alice',
|
||||||
|
age: 30,
|
||||||
|
address: {
|
||||||
|
city: 'New York',
|
||||||
|
zip: '10001'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 修改一级属性会触发响应式更新
|
||||||
|
user.name = 'Bob'; // 响应式触发
|
||||||
|
|
||||||
|
// 修改嵌套属性不会触发响应式更新
|
||||||
|
user.address.city = 'Los Angeles'; // 不会触发响应式更新
|
Loading…
x
Reference in New Issue
Block a user