Skip to content

Instantly share code, notes, and snippets.

@wordijp
Last active July 8, 2022 14:54
Show Gist options
  • Save wordijp/0c9dee48bbfad15198e321e224f40196 to your computer and use it in GitHub Desktop.
Save wordijp/0c9dee48bbfad15198e321e224f40196 to your computer and use it in GitHub Desktop.
Vue 3 での注意点

nuxt v3.0.0-rc.4時点

リアクティブ変数の.valueはtemplate内では浅い展開しかされない

template内でObjectネストされている場合などで .value を省く事は出来ない
vuejs/core/issues/5921

<script setup lang="ts">
import { toRefs, reactive } from 'vue';

const state = toRefs(reactive({
  array: [1, 2, 3, 4, 5],
  hoge: {
    piyo: 'piyopiyo',
  },
});
</script>

<template>
  <!-- NG -->
  {{ state.array[0] }} 
  {{ state.hoge.piyo }}
  <ul>
    <li v-for="x in state.array">
      {{ x }}
    </li>
  </ul>
  
  <!-- 明示的な.valueが必要 -->
  {{ state.array.value[0] }}
  {{ state.hoge.value.piyo }}
  <ul>
    <li v-for="x in state.array.value">
      {{ x }}
    </li>
  </ul>
</template>

新しいcomponentsをtemplateに追加した時はHMRされない

たぶんRC版だから、リリース版に期待 npmじゃなくyarnを使う

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment