2017-03-03 113 views
1

我試着與溫泉UI設置vuejs和我得到這個錯誤:錯誤:未捕獲的類型錯誤:Vue.util.hyphenate不是一個函數

Error: Uncaught TypeError: Vue.util.hyphenate is not a function

這裏是整個代碼:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/onsen/2.1.0/css/onsenui.css"> 
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/onsen/2.1.0/css/onsen-css-components.min.css"> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.1/vue.js"></script> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/onsen/2.1.0/js/onsenui.js">  </script> 
    <script src="https://unpkg.com/[email protected]"></script> 
</head> 
<body> 
    <div id="app"></div> 
</body> 
<script> 
    var vm = new Vue({ 
    el: '#app', 
    template: 
     '<v-ons-page>\ 
     <v-ons-toolbar>\ 
      <div class="center"> Title </div>\ 
     </v-ons-toolbar>\ 
     <p style="text-align: center">\ 
      <v-ons-button @click="$notification.alert(\'Hello World!\')">Click</v-ons-button>\ 
     </p>\ 
     </v-ons-page>' 
    }); 
</script> 
</html> 

我找不到這是一個已知的問題。我也嘗試使用2.0.0之類的舊版本od vue。

任何人都可以幫忙嗎?

回答

2

先生,我遇到了與你同樣的錯誤,我試圖找到錯誤並解決它。 首先,下載「https://unpkg.com/[email protected]」,並將腳本dom的src更改爲本地的。 然後你就可以打開 「[email protected]」,找到這些代碼:

var register = function register(Vue, type, items) { 
 
\t (0, _keys2.default)(items).forEach(function (key) { 
 
\t  var value = items[key]; 
 
\t  key = Vue.util.hyphenate(key); 
 
\t  Vue[type](key, value); 
 
\t }); 
 
\t };

所以,你可以看到 「Vue.util.hyphenate」但現在vue沒有這個功能。請使用該文件中的相同功能。

例如:

var register = function register(Vue, type, items) { 
 
\t (0, _keys2.default)(items).forEach(function (key) { 
 
\t  var value = items[key]; 
 
\t  var hyphenate = function hyphenate(string) { 
 
\t \t \t return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); 
 
\t \t }; 
 
\t  key = hyphenate(key); 
 
\t  Vue[type](key, value); 
 
\t }); 
 
\t };

我的英語不好使了,遺憾地使用你的時間。

1

在上一個版本Vue.js中,Vue.util上的許多暴露方法和屬性已被刪除。

所以,你需要在67線下載JavaScript文件(https://unpkg.com/[email protected])和替換代碼:

key = Vue.util.hyphenate(key);

這個代碼:

key = key.replace(/([a-zA-Z])([A-Z])/g, '$1-$2').toLowerCase();

相關問題