现在我们来看一下vue中的数据监听事件$watch,
js代码:
new Vue({
el:"#div",
data:{
arr:[1,2,3]
}
}).$watch("arr",function () {
alert("数据改变了")
})html代码:
{{arr}}
这就是数组的监听,对于json我们也是一样的,但是我们得给他一个深度监听,$watch的第三个参数{deep:true}。
angular 中的数据交互有$http,同样对于vue我们也是有数据交互的,有post,get以及jsonp的方法。
立即学习“前端免费学习笔记(深入)”;
我们在这里做一个简单的百度搜索功能
css代码:
除了有一半电子商务的全部基本功能外,还增加了“模版自由更换”“程序在线自动更新升级”“分布式搜索”等特色功能 主要功能: ·网站的基本信息设置,部分数据以XML方式同服务器发生交互。 ·可自行关闭和开启网站,方便维护,可自定维护时显示的代码。 ·可自定义站点的关键字和描述,方便搜索引擎找到您的网站。 ·可自定义商品图片、新闻图片的上传目录和预览图片的大小。 ·提供自己设置网站的邮件发送服务器SM
a{
text-decoration: none;
color: black;
}
#div{
text-align: center;
padding-top: 50px;
}
input{
height: 25px;
width: 500px;
border-radius: 5px;
outline: none;
}
ul{
margin-left:470px;
margin-top: 0;
}
li{
height: 25px;
text-align: left;
border:1px solid gray;
list-style: none;
width: 500px;
}
js代码:
new Vue({
el:"#div",
data:{
msg:" ",
arr:[]
},
methods:{get:function () {this.$http.jsonp('',{
wd:this.msg
},{
jsonp: 'cb'}).then(function(res){this.arr=res.data.s
},function(s){
console.log(s);
});
}
}
})html代码:
这样一个简单的小案例就做好了。









