方法
<script setup>
function getParam(param) {
return param;
}
</script>
<template>
{{ getParam(1) }}
</template>
响应式数据声明
import { ref, reactive } from 'vue'
const enabled = ref(true)
const object = reactive({ variable: false })
组件声明
import { defineAsyncComponent } from "vue";
import TheComponent from "./components/TheComponent.vue";
const AsyncComponent = defineAsyncComponent(() =>
import("./components/AsyncComponent.vue")
);
观察者
import { watch, ref } from "vue";
const counter = ref(0);
watch(counter, () => {
console.log("Counter value changed");
});
生命周期钩子
import { onMounted } from "vue";
console.log("Equivalent to created hook");
onMounted(() => {
console.log("Mounted hook called");
});
定义 emits
const emit = defineEmits(["event-name"]);
function emitEvent() {
emit("event-name");
}
定义属性
defineProps({
elements: Array,
counter: {
type: Number,
default: 0,
},
});
正文结束
Ctrl + Enter