
Vue3
小仓桑
I want something just like this
展开
-
Vue3中setup调用生命周期钩子函数
介绍如果要在setup方法中调用组件生命周期钩子函数:在原来的生命周期钩子函数名称前加on关键字,并且需要保持小驼峰的命名方式。语法import {onMounted, onUpdated} from 'vue'export default { name: "Lifecycle", setup() { onMounted(() => { console.log("组件视图挂载完成") }); onUpdated(() => {原创 2022-01-08 19:53:04 · 4459 阅读 · 0 评论 -
Vue3的watch与computed
watch介绍通过计算属性我们能拿到处理后的数据, 但是通过函数我们也能拿到处理后的数据,只要返回的结果没有发生变化, 那么计算属性就只会被执行一次。Vue3写法setup() { const name = ref('漩涡鸣人'); const {username, password} = toRefs(reactive({ username: '宇智波带土', password: 'zs1262597806' })) watch原创 2022-01-08 12:22:23 · 1286 阅读 · 0 评论 -
vue3中computed的使用方式
用法import { computed, ref } from "@vue/reactivity";export default { setup() { const msg = ref("宇智波带土"); // 实现msg反转操作 const reverseMsg = computed(() => { return msg.value.split("").reverse().join(""); }); return { msg原创 2022-01-06 23:13:23 · 1294 阅读 · 0 评论 -
Vue动态改变数据
方式一:reactive注意点reactive参数必须是对象使用方式import { reactive} from "vue";export default { setup() { const obj = reactive({ name: "张三", }); return obj; }, methods: { updataName() { console.log("方法进来啦!"原创 2022-01-06 22:54:34 · 1316 阅读 · 0 评论