代码语言:javascript复制
<html>
<body>
<input type="text" id="myinput">
</body>
<script>
var myinput = document.querySelector('#myinput');
function Vue() {
}
Vue.Use = function (F, options) {
F(this, options);
}
var VueState = function install(VueObj, state) {
Object.defineProperty(VueObj.prototype, '$state', {
get: () => state
})
};
Vue.Use(VueState, {
age: 18,
name: 'Liu Yi'
});
var vue = new Vue();
myinput.value = vue.$state.name;
console.log('myinput.value', myinput.value);
</script>
</html>