2017-03-03 77 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();

相关问题