Answer the question
In order to leave comments, you need to log in
How to include third-party libraries (like jquery, form-serializer, etc.) in vue.js?
Unable to include third party libraries in vue.js
main.js
...
require('jquery')
import Vue from 'vue'
import VueMdl from 'vue-mdl'
import App from './App'
import Auth from './views/user/Auth'
import Index from './views/Index'
import VueRouter from 'vue-router'
import VueResource from 'vue-resource'
Vue.use(VueRouter)
Vue.use(VueMdl)
Vue.use(VueResource)
const AppComponent = Vue.extend(App)
new AppComponent({
router,
el: '#app',
template: '<App/>',
components: { App }
})
<template>
...
</template>
<script>
export default {
name: 'register',
data () {
return {
msg: 'Register'
}
},
methods: {
open () {
this.$refs.register.open()
},
close () {
this.$refs.register.close()
},
submit () {
var data = $('form').serialize() // '$' is not defined
console.log(jQuery) // 'jQuery' is not defined
console.log(data);
}
}
}
</script>
plugins: [
new webpack.ProvidePlugin({
$ : "jquery",
jQuery : "jquery",
})
],
Answer the question
In order to leave comments, you need to log in
missed the fact that there is jquery + bootstrap + lodash connection out of the box
So you explicitly write imports in RegisterModal.vue itself, then what you wrote jquery import in main.js, so it will only be visible in the scope of this file:
<script>
import $ from 'jquery';
export default {
name: 'register',
...
}
</script>
It is enough to write in index.html
script src=" https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.... "
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question