sunmingtao / sample-code

3 stars 4 forks source link

Vue js 3: Uncaught TypeError: Vue.use is not a function #249

Closed sunmingtao closed 3 years ago

sunmingtao commented 3 years ago

Import VueResource as below in Vue js 3

const Vue = require('vue')
const VueResource = require('vue-resource');

Vue.use(VueResource)
createApp(App).mount('#app')

Browser console

image

sunmingtao commented 3 years ago

Vue.use(...) is Vue js 2 syntax. The new syntax is:

import { createApp } from 'vue'
import App from './App.vue'
const VueResource = require('vue-resource');

createApp(App).use(VueResource).mount('#app')
sunmingtao commented 3 years ago

But this.$http.get("http://...")... doesn't work. It complains "this.$http is undefined".

It looks like vue-resource is not compatible with Vue 3.

sunmingtao commented 3 years ago

Another issue https://github.com/sunmingtao/sample-code/issues/251 covers this. Hence closed