2017-03-18 64 views
0

我正在使用Vue 2.0 + VueRouter並嘗試將VueMdl(https://posva.net/vue-mdl/#/usage)組件集成到我的項目中。VueMdl組件未正確註冊

該網站作爲Spring Boot使用嵌入式Apache Tomcat提供的靜態資源運行,因此請考慮前端未在NodeJs環境中運行。

問題是我找不出爲什麼VueMdl組件未正確註冊。 require()函數不起作用,因爲它特定於NodeJs,並且在瀏覽器開發人員控制檯中,如果鍵入VueMdl或console.log(VueMdl)...我可以看到該對象也已定義。

謝謝你在前進,

app.js

const router = new VueRouter({ 
    routes: routes 
}) 

// load main Vue.js app 
var app = new Vue({ 
    el: '#app', 
    router: router, 
    components: VueMdl.components, 
    directives: VueMdl.directives 
}) 

的index.html

<html> 
    <head> 
    [....] 
    </head> 
    <body> 
    [....] 
    <script src="https://unpkg.com/vue/dist/vue.js"></script> 
    <script src="https://unpkg.com/vue-router/dist/vue-router.min.js"></script> 
    <script src="//rawgit.com/posva/vue-mdl/master/dist/vue-mdl.min.js"></script> 
    <script src="app.js"></script>  
    </body> 
</html> 

錯誤文本

[Vue warn]: Unknown custom element: <mdl-textfield> - did you register the 
component correctly? For recursive components, make sure to provide the "name" option. 
(found in <Anonymous> - use the "name" option for better debugging messages.) 

回答

0

我認爲你需要導入它:

var VueMdl = require('vue-mdl'); 
+0

我不使用的NodeJS,的WebPack或其他新的東西...我會嘗試添加http://requirejs.org/docs/download.html –

+0

在此之前,嘗試'Vue.use(VueMdl )'看看它是否會起作用。 –

+0

今天我會讓你知道...稍後 –