Я новичок в vuejs. Я работаю в vue проекте, используя vue -cli
- Я установил vue vue / cli с
npm install -g @vue/cli
- Я создал проект с
vue init webpack my-project
- Я установил jQuery с
npm install jquery
- Я установил материализацию - css с
npm install materialize-css
- Все хорошо после
npm run dev
- Но когда я выполняю
npm run buid
и запускаю файл index. html, который находится в каталоге dist, я получаю эту ошибку в chrome devtools
Uncaught TypeError: c(...)(...).modal is not a function
at HTMLDocument.<anonymous> (App.vue:20)
at l (jquery.js:3557)
at d (jquery.js:3625)
My main. js
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import vueResource from 'vue-resource'
import store from './components/store/AuthStore'
import 'materialize-css'
import 'materialize-css/dist/css/materialize.min.css'
let currentUrl = window.location.href
let url = new URL(currentUrl)
let tokenFromUrl = url.searchParams.get('token')
let nameFromUrl = url.searchParams.get('name')
let avatarFromUrl = url.searchParams.get('avatar_link')
if (tokenFromUrl) {
localStorage.setItem('token', tokenFromUrl)
localStorage.setItem('name', nameFromUrl)
localStorage.setItem('avatar_link', avatarFromUrl)
}
let token = localStorage.getItem('token') ? localStorage.getItem('token') : ''
Vue.config.productionTip = false
Vue.prototype.$hostname = (Vue.config.productionTip) ? 'https://ipaq-mobile.000webhostapp.com/traitement' : 'http://127.0.0.1:8000'
Vue.prototype.$avatar_link = localStorage.getItem('avatar_link')
Vue.use(vueResource)
Vue.http.options.root = (Vue.config.productionTip) ? 'https://ipaq-mobile.000webhostapp.com/traitement/api' : 'http://127.0.0.1:8000/api'
Vue.http.headers.common['Access-Control-Allow-Headers'] = 'Origin, Accept, Authorisation'
Vue.http.headers.common['Accept'] = 'application/json'
Vue.http.headers.common['Authorization'] = 'Bearer ' + token
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
store,
components: { App },
template: '<App/>'
})
Мое приложение. vue
<template>
<div id="app">
<div class="navbar">
<router-view name="navbar" v-bind:pathName="pathName"/>
<!-- <div @click="loadMore = !loadMore"><h1><a>loadMore</a></h1></div> -->
</div>
<SideNav></SideNav>
<router-view name="main"></router-view>
</div>
</template>
<script>
import SideNav from './components/TheSideNav'
import $ from 'jquery'
export default {
name: 'App',
mounted: function () {
$(document).ready(function () {
$('.modal').modal()
$('.sidenav').sidenav()
})
},
components: {
SideNav
},
computed: {
pathName () {
return this.$route.name
}
}
}
</script>
<style>
</style>
Как это исправить?