如下代码: function inline 22 & output inline 42
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<meta http-equiv='X-UA-Compatible' content='ie=edge'>
<title>vue 插件 mixin混入Vue实例中</title>
</head>
<body>
<script src="https://vuejs.org/js/vue.js"></script>
<script type="text/javascript">
var get = function (a) {
console.log('Hello ' + a)
}
var plugin = {}
plugin.install = function (Vue) {
if (plugin.installed) {
return;
}
Vue.who = get
Object.defineProperties(Vue.prototype, {
$who: {
get() {
return { get: get }
}
}
})
Vue.mixin({
created: function () {
console.log('Plugin activiated')
}
})
}
if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(plugin)
}
var Vue = new Vue()
Vue.$who.get('Vue Instance')
Vue.who('Global Vue')
</script>
</body>
</html>