VUE框架this

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="vue3.js"></script>

</head>
<body>

<div id="app">
//单机
<p @click="foo('hulanxi1')">{{msg}}</p>
//双击
<p @dblick="foo('hulanxi2')">{{msg}}</p>

</div>

<script>

// 数据驱动界面
var vm = Vue.createApp({
data(){
return {
msg:"huchangxi",
books2: [
{title: "西游记", price: 199},
{title: "水浒传", price: 299},
{title: "三国演义", price: 399},
{title: "红楼梦", price: 499}
]
}
},
methods: {
foo(name){
this.msg = name;
console.log(this);// vm对象
var that = this;
this.books2.filter(function () {
console.log("::",this); // window对象
console.log(":::",that); // window对象
})
},

},
}).mount("#app")

</script>

</body>
</html>

 

posted @   呼长喜  阅读(27)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示