我尝试使用 onsen ui 设置 vuejs,但收到此错误:
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/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1e686b7b3371706d7b706b775e2c302e302e337f726e767f302e" rel="noreferrer noopener nofollow">[email protected]</a>"></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>
我找不到这是已知问题。我也尝试过使用旧版本的 od vue,例如 2.0.0。
有人可以帮忙吗?
最佳答案
先生,我遇到了和你一样的错误,我正在尝试找到错误并解决它。 首先,下载“https://unpkg.com/[email protected]”,并将脚本dom的src更改为本地的。 然后你可以打开“[email protected]”并找到这些代码:
var register = function register(Vue, type, items) {
(0, _keys2.default)(items).forEach(function (key) {
var value = items[key];
key = Vue.util.hyphenate(key);
Vue[type](key, value);
});
};
所以你可以看到“Vue.util.hyphenate”,但是现在vue没有这个功能。请使用此文件中的相同函数。
例如:
var register = function register(Vue, type, items) {
(0, _keys2.default)(items).forEach(function (key) {
var value = items[key];
var hyphenate = function hyphenate(string) {
return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
};
key = hyphenate(key);
Vue[type](key, value);
});
};
我的英语很差,很抱歉占用您的时间。
关于vue.js - 错误 : Uncaught TypeError: Vue. util.hyphenate 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42577989/