2.7 — Upgrade Vue 2.6 To
// vue.config.js (vue-cli) module.exports = chainWebpack: config => config.module .rule('vue') .use('vue-loader') .tap(options => ( ...options, reactivityTransform: true, )); , ; Then write:
</script> <script setup> import ref from 'vue' const count = ref(0) </script> <template> <button @click="count++"> count </button> </template> Optional chaining and nullish coalescing <template> <div> user?.address?.city ?? 'Unknown' </div> </template> Reactivity Transform (opt-in) Enable via vue-loader config:
- this.$scopedSlots.header(data) + this.$slots.header(data) Functional components using the functional: true option or <template functional> still work, but the performance benefit is minimal. Consider migrating to normal components. 4. props validation Default factory functions no longer have access to this . Use arrow functions or external helpers. New Features to Start Using Composition API (no extra import) <script> import ref, onMounted from 'vue' export default setup() const count = ref(0) onMounted(() => console.log('mounted')) return count upgrade vue 2.6 to 2.7
module.exports = extends: ['plugin:vue/vue3-recommended'], // yes, 'vue3' works for 2.7 ; Most apps work without changes. But be aware of these: 1. v-model on custom components Vue 2.7 aligns with Vue 3’s v-model behavior. Previously, v-model on a component compiled to value + input . Now it compiles to modelValue + update:modelValue .
"dependencies": "vue": "^2.7.14"
| Package | Old version (example) | New version | |---------|----------------------|--------------| | vue-template-compiler | 2.6.x | Remove (no longer needed) | | @vue/composition-api | any | Remove (built-in now) | | vue-loader | 15.x | ^15.10.0 | | vue-style-loader | any | no change needed | Remove vue-template-compiler Vue 2.7 uses an internal template compiler – you no longer need the separate package.
npm uninstall vue-template-compiler npm uninstall @vue/composition-api Then update imports: // vue
Update tsconfig.json :