Migration Guide Cheat Sheet
Migration Guide Cheat Sheet
VUE 2
<template functional>
<h1>{{ text }}</h1>
<ItemList>
</template>
<template slot="heading" slot-scope="slotProps">
<h1>My Heading for {{ slotProps.items.length }} items</h1> <script> Need to remove
</template> export default { this attribute.
</ItemList> props: ['text']
}
VUE 3 </script>
<ItemList>
<template v-slot:heading="slotProps">
<h1>My Heading for {{ slotProps.items.length }} items</h1>
</template> Four learning paths to expand your Vue skills.
</ItemList> Find yours here vuemastery.com/courses
VUE 2
This used to run first. <html lang>
<ul> <head>...</head>
<li v-for="num in nums" v-if="num < 10">{{ num }}</li> <body>
</ul> <noscript></noscript>
<div id="app" data-v-app>
VUE 3 <div id="app" data-v-7ba
Now, this runs first. ...
<ul> </div> Now the mounted container
<li v-for="num in nums" v-if="num < 10">{{ num }}</li> </div> will still be there, so you might
</ul> ... get two container elements in
the rendered HTML.
SOLUTION
<ul>
<li v-for="num in nums"> Transition Classes
<span v-if="num < 10" :key="myKey">{{ num }}</span> (This deprecation has no warnings in the migration build.)
<span v-else class="high" :key="myKey">{{ num }}</span>
VUE 2 VUE 3
</li>
</ul> Rename
.v-enter .v-enter-from
Now you can’t use the same key for branches in the same Rename
conditional, either remove them all or use different keys. .v-enter .v-enter-from
Looking for more information? We have a blog series that you can dive into now.
Visit vuemastery.com/blog/migration
Vue Mastery
VUE 2 VUE 3
import Vue from "vue" import { createApp } from 'vue' Import the function
import App from './App.vue' import App from './App.vue' instead of the object.
import router from './router' import router from './router'
import store from './store' import store from './store'
Vue.component('my-heading', { app.component('my-heading', {
props: [ 'text' ], props: [ 'text' ],
template: '<h1>{{ text }}</h1>' template: '<h1>{{ text }}</h1>'
}) })
VUE 2 VUE 3
const app = new Vue(App) No dollar sign prefix. Global APIs Instance APIs
VUE 2 VUE 3
Async Component
COMPONENT_ASYNC
v-for References
V_FOR_REF
import { defineAsyncComponent } from 'vue'
...
mounted () {
Our blog series will show you a workaround for this. console.log(this.$refs.myNodes)
Find it here vuemastery.com/blog/migration }
Workaround
Vue Mastery
Lifecycle Hooks
OPTIONS_BEFORE_DESTROY / OPTIONS_BEFORE_DESTROY
VUE 2 VUE 3
VUE 2 VUE 3
Vue.directive('my-directive', { app.directive('my-directive', {
created() { created() {
... ...
}, Rename },
bind() { beforeMount() {
... ...
}, Rename },
inserted() { mounted() {
... ...
}, },
update() { Removed beforeUpdate() { NEW
...
}, Rename },
componentUpdated() { updated() {
... ...
}, },
beforeUnmount() { NEW
...
Rename },
unbind() { ... } unmounted() { ... }
}) })
vm.$on Removed
<MyComponent v-model:title="myString" />
vm.$off Removed
vm.$once Removed
Workaround
Native Event
COMPILER_V_ON_NATIVE Listeners
Need to remove the native modifier. INSTANCE_LISTENERS
Filters
FILTERS
VUE 2 VUE 3
<template> <template>
<p>{{ num | roundDown }}</p> <p>{{ numRoundedDown }}</p>
</template> </template>
Filters won’t work anymore. Use computed properties instead.
... ...
filters: { computed: {
roundDown(value) { numRoundedDown() {
return Math.floor(value) return Math.floor(this.num)
} }
}, },