Mon Jun 5 15:37:00 UTC 2023 inscode

上级 761544ce
<script setup> <script setup>
import { onMounted, onUpdated, reactive,ref } from 'vue';
import HelloWorld from './components/HelloWorld.vue' import HelloWorld from './components/HelloWorld.vue'
import TheWelcome from './components/TheWelcome.vue' import TheWelcome from './components/TheWelcome.vue'
const age=ref(0)
const editAge = ()=>{
age.value++
}
</script> </script>
<template> <template>
<header> <header>
<img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" /> <img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" />
年龄{{ age }}
<div class="wrapper"> <div class="wrapper">
<HelloWorld msg="You did ithahahh!" /> <HelloWorld @editAge="editAge" msg="我是传过来的值"/>
</div> </div>
</header> </header>
......
<script setup> <script setup>
import { onMounted, onUpdated, reactive,ref } from 'vue'; import { onMounted, onUpdated, reactive, ref, computed, watchEffect, watch } from 'vue';
const obj=reactive({ const obj = reactive({
name:'kjp' name: 'kjp'
}) })
const ha=ref(6) const person = reactive({
console.log('22222') books: [
'Vue 2 - Advanced Guide',
'Vue 3 - Basic Guide',
'Vue 4 - The Mystery'
]
})
defineProps({ defineProps({
msg: { msg: String
type: String,
required: true
}
}) })
function edit(){ const ha = ref(6)
obj.name='ppppp' const emits = defineEmits(['editAge'])
ha.value=77 function edit() {
obj.name = 'ppppp'
ha.value = 77
}
function buttonAge() {
console.log('22222')
emits('editAge')
} }
onMounted(()=>{
console.log('555555')
console.log(ha.value)
const com = computed(() => {
return person.books.length > 0 ? "有很多书" : '没有书'
}) })
onUpdated(()=>{
watchEffect(() => {
console.log('新监听' + obj.name);
})
watch(obj.name, (n, o) => {
console.log('新值:' + n, '旧值' + o)
}, {deep:true})
onMounted(() => {
console.log('555555')
console.log(ha.value)
})
onUpdated(() => {
console.log() console.log()
}) })
</script> </script>
<template> <template>
<div class="greetings"> <div class="greetings">
<h1 class="green">{{ msg }}</h1> <h1 class="green">222</h1>
<h3> <!-- <h3>
You’ve successfully created a project with You’ve successfully created a project with
<a target="_blank" href="https://vitejs.dev/">Vite</a> + <a target="_blank" href="https://vitejs.dev/">Vite</a> +
<a target="_blank" href="https://vuejs.org/">Vue 3</a>. <a target="_blank" href="https://vuejs.org/">Vue 3</a>.
</h3> </h3> -->
<h2>姓名:{{ obj.name }}</h2>年龄:{{ ha }} <h2>姓名:{{ obj.name }}</h2>年龄:{{ ha }}
<span>父传子:{{ msg }}</span>
<p>{{ com }}</p>
<button @click='edit'>修改名字</button> <button @click='edit'>修改名字</button>
<button @click='buttonAge'>修改年龄</button>
</div> </div>
</template> </template>
...@@ -55,6 +78,7 @@ h3 { ...@@ -55,6 +78,7 @@ h3 {
} }
@media (min-width: 1024px) { @media (min-width: 1024px) {
.greetings h1, .greetings h1,
.greetings h3 { .greetings h3 {
text-align: left; text-align: left;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册