<!DOCTYPE html>
<html>
<head>
<script src="../vue2.4.4.js"><script>
<script src="../vue-resource.js"></script>
</head>
<body>
<div id="app">
{{ name }}
</div>
<script>
new Vue({
el:"#app",
data:{
name;" "
},
methods: {
},
created: function(){
//发送请求到服务器加载数据
//vue-resources 发送get请求
/* this.$http.get("http://www.cnblogs.com/api/getprodlist").then(function(result) {
var res = result.body;
this.name = res.message[0].name;
}); */
//vue-resource 发送post 请求
this.$http.post("http://www.cnblogs.com/api/addproduct",{"name":"小明"}).then(function(result) {
var res = result.body;
alert(res.message);
});
}
})
</script>
</html>