Answer the question
In order to leave comments, you need to log in
Webpack + Vue.js + jQuery Plugin: Why "is not a function"?
There is such a library: https://github.com/hernansartorio/jquery-nice-select
I include it in the bootstrap.js file like this:
Then I try to use it already in the application in the app.js file :
require('jquery-nice-select');
require('./bootstrap');
// .. код с настройками Vue
const app = new Vue({
router,
components: {
App
},
template: '<app></app>',
mounted() {
$('select').niceSelect();
}
}).$mount('#app');
mix
.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/vendors.scss', 'public/css')
.sass('resources/assets/sass/style.scss', 'public/css')
.extract(
[
'vue',
'vue-resource',
'vue-router',
'vue-scrollto',
'vue-meta'
],
'public/js/vue.js'
)
.extract(
[
'jquery',
'bootstrap-sass',
'jquery-nice-select',
'owl.carousel',
'jquery-parallax.js',
],
'public/js/vendor.js'
)
.autoload({
'jquery': ['$', 'jquery', 'jQuery', 'window.jQuery'],
'tether': ['window.Tether', 'Tether'],
})
;
vue.js:484 [Vue warn]: Error in mounted hook: "TypeError: $(...).niceSelect is not a function"
TypeError: $(...).niceSelect is not a function
<!-- код -->
<script src="{{ mix('/js/manifest.js') }}"></script>
<script src="{{ mix('/js/vendor.js') }}"></script>
<script src="{{ mix('/js/vue.js') }}"></script>
<script src="{{ mix('/js/app.js') }}"></script>
Answer the question
In order to leave comments, you need to log in
I would suggest moving jQuery to js:
global.jquery = global.jQuery = global.$ = require('jquery');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question