标签:log 组件 loading 技术 less 方法 rom png object
npm i -g create-vite-app
vue3test-project是项目名称
create-vite-app vue3test-project
import { reactive, toRefs, onMounted, computed, watch, watchEffect } from ‘vue‘;
import { useRouter } from ‘vue-router‘
<template>
<div @click="test()">
1234567
</div>
</template>
<script>
import { reactive, toRefs, onMounted, computed, watch, watchEffect } from ‘vue‘;
export default {
setup() {
const state = reactive({
// 这里写原来的data
});
onMounted(() => {});
function test() {
// 方法要return出去
}
return {
...toRefs(state),
test
};
}
};
</script>
<style lang="less" scoped>
</style>
const state = reactive({
type: 1
});
console.log(state.type);
watchEffect( () => {
console.log(state.type, ‘改变‘)
})
watch(() => state.type, (newValue, oldValue) => {
console.log(type, ‘改变‘)
})
父组件:
<template>
<test :type="type"/>
</template>
子组件:
export default {
name: ‘test‘,
props: {
detail: {
type: Object,
default: {}
}
}
setup(props) {
console.log(props.type);
}
}
父组件:
<template>
<test @onjieshou="jieshou"/>
</template>
function jieshou(value) {
console.log(value); // value是1
}
子组件:
export default {
name: ‘test‘,
emits: [‘onjieshou‘],
setup(props, { emit }) {
function test() {
emit(‘onjieshou‘, 1);
}
}
}
标签:log 组件 loading 技术 less 方法 rom png object
原文地址:https://www.cnblogs.com/lzb1234/p/14823206.html