vue3.0 Composition API 中 setup 使用

vue3.0 Composition API 中 setup 使用

介绍

setup 简单来说就像 react 一样,你的数据定义不用放到 data, 方法不用放到 methods, 只需要一个 setup 全部搞定,不用像有些复杂的项目,接口一堆,写一会忘了上面定义的变量参数,可以一块一块来写,结合jsx 更加方便,写起来很舒服

使用

import { defineComponent, ref, reactive } from "vue";

export const VisualEditor = defineComponent({
    props: {},
    setup (props) {
                const readersNumber = ref(0)
                const book = reactive({ title: 'Vue 3 Guide' })
                const readerHtml = () => {
            <span class="text">
               hello world
            </span>
        }
        return {
                    readersNumber,
                    book,
                    readerHtml
                }
    }
})

发表评论

您的电子邮箱地址不会被公开。