在vue3.2中,组件中定义的变量和方法不再需要return了,而是可以直接在模板中使用。

<script setup>
import { ref } from 'vue'

const text = ref('点击')

const handleClick = () => {
  console.log('click')
}
</script>

<template>
  <button @click="handleClick">{{ text }}</button>
</template>

就如上面的例子所展示的那样,组件中定义的变量或是方法,可以直接在模板中使用,那么如果引入的组件该如何在模板中使用呢?

在vue3.x中,引入的组件是需要在components中声明的,但是在vue3.2中,你可以直接使用。

还是上例子吧。

<script setup>
import CustomComponent from './CustomComponent/main.vue'
</script>

<template>
  <CustomComponent></CustomComponent>
</template>

你没有看错,就是这么简单。

Logo

智屏生态联盟致力于大屏生态发展,利用大屏快应用技术降低开发者开发、发布大屏应用门槛

更多推荐