Vue3 給組件設置name

在Vue3的<script setup>模式下,往往會忽略 name;

但是在keep-alive等情況下又需要用到!

方法1:

<script lang="ts">
  export default {
    name: "my-component"
  }
</script>

<script lang="ts" setup>
  /* 業務代碼 */
</script>

方法2:

<script lang="ts" setup>
  //改方法需要vue3.3+
defineOptions({ name:
"my-component" }) </script>

方法3:這裏主要是在動態加載路由時

 const comp=import(`@/component.vue`)
  comp.then(res=>{
         res.default.name=item.name
})

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章