vue学习

This commit is contained in:
yingfeng.ai 2024-11-08 14:19:30 +08:00
parent 0f623c5fb6
commit a3225b9989
5 changed files with 94 additions and 33 deletions

View File

@ -42,10 +42,12 @@
padding: 20px;
border-radius: 10px;
}
.content {
display: flex;
justify-content: space-evenly;
}
img, video {
width: 100%;
}

View File

@ -7,6 +7,7 @@
<script setup lang="ts" name="Game">
import {reactive} from 'vue'
let games = reactive([
{id: 'asgytdfats01', name: '英雄联盟'},
{id: 'asgytdfats02', name: '王者农药'},
@ -23,6 +24,7 @@
border-radius: 10px;
box-shadow: 0 0 10px;
}
h2 {
background-color: orange;
text-align: center;

View File

@ -3,6 +3,7 @@
<h3>父组件</h3>
<div class="content">
<Category title="热门游戏列表">
<!-- 根据子组建的 <slot>默认内容</slot> 显示内容-->
<ul>
<li v-for="g in games" :key="g.id">{{ g.name }}</li>
</ul>

View File

@ -0,0 +1,29 @@
// 引入mitt
import mitt from 'mitt'
// 调用mitt得到emitteremitter能绑定事件、触发事件
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

View 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'; //