Ai
1 Star 0 Fork 1

aeipyuan/vue3学习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index.html 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
aeipyuan 提交于 2020-04-06 20:31 +08:00 . 简单实现vue3响应
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>vue3</title>
</head>
<body>
<div id="container"></div>
<script src="./vue.global.js"></script>
<script>
function usePosition() {
const position = Vue.reactive({ x: 0, y: 0 });
function update(e) {
position.x = e.pageX;
position.y = e.pageY;
}
/* 挂载 */
Vue.onMounted(() => {
window.addEventListener('mousemove', update);
})
/* 卸载 */
Vue.onUnmounted(() => {
window.removeEventListener('mousemove')
})
return Vue.toRefs(position);
}
/* composition API */
const App = {
setup() {
let state = Vue.reactive({ name: "AEIP源" });
function change() {
state.name = "aeipyuan";
}
let { x, y } = usePosition();
return {
state, change,
x, y
}
},
template: `<div @click="change">{{state.name}} x:{{x}} y:{{y}}</div>`
}
/* 创建 */
Vue.createApp(App).mount('#container');
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/aeipyuan/simple_implementation_of_vue3.git
git@gitee.com:aeipyuan/simple_implementation_of_vue3.git
aeipyuan
simple_implementation_of_vue3
vue3学习
master

搜索帮助