vue3 setup便捷开发

其实到了vue3 官方所指的耦合 很多成分意思是 希望大家将代码都写在 setup中

<template>
  <div style = "padding: 10px;">
      {
   
   { information }}
  </div>
</template>

<script>
import {
      
       ref } from 'vue'
export default {
      
      
  setup(){
      
      
    const information = ref(13241324)
    return {
      
      
      information
    }
  }
};
</script>
<style>
</style>

我们就可以将其改成

<template>
  <div style = "padding: 10px;">
      {
   
   { information }}
  </div>
</template>

<script setup>
import {
      
       ref } from 'vue'
const information = ref(13241324)
</script>
<style>
</style>

在这里插入图片描述
效果也是一样的 这样开发 在

<script setup>

中 以const声明的函数 以及reactive ref声明的数据都不需要返回 直接成为响应式数据 可在界面中使用

猜你喜欢

转载自blog.csdn.net/weixin_45966674/article/details/131125154