Today I Learned - Rocky Kev

TIL chaining Vue 3 Main.js

POSTED ON:

TAGS:

Pretty newbie unknown.

When you scaffold a Vue 3 project, your main js file looks like this.

Within main.js:

import { createApp } from "vue";
import App from "./App.vue";

createApp(App).mount("#app");

But let's say you wanted to get axios or whatever plugin included.
Axios-vue wants:

import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'

const app = Vue.createApp(...)
app.use(VueAxios, axios)

It's essentially chaining commands.
So to make it follow that Vue 3 pattern that was established:

import { createApp } from 'vue'
import App from './App.vue'
import axios from 'axios'
import VueAxios from 'vue-axios'

createApp(App).use(VueAxios, axios).mount("#app");

Via:
https://stackoverflow.com/a/64273694/4096078


Related TILs

Tagged:

TIL How to implement two-way binding without a framework

One of the reasons we use React or Vue is because of that sweet sweet two-way binding. It's the automatic syncing of data between the model (data) and the view (UI) in both directions. Any changes made to the data will automatically update the view, and any changes made to the view will automatically update the data.

TIL Cherry-picking out of bootstrap-vue

If you are using a component library that uses ES modules like bootstrap-vue, you can cherry pick its components instead of just registering all of them globally.

TIL how Svelte is different fom Vue/React