<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>错误的用法</title>
</head>
<body>
<div id="app">
{{sayHello()}}
</div>
<script src="../js/vue.js"></script>
<script>
let user = {
name:'liu',
city:'beijing'
};
let vm = new Vue({
el:'#app',
data:user,
methods:{
sayHello:()=> `欢迎来自${this.city}的${this.name}!`
}
});
/*
箭头函数不是绑定的自己的this指针,实际上是windows对象
*/
</script>
</body>
</html>
vue-前端第2章instance05.html
最新推荐文章于 2024-11-10 15:10:09 发布