生命周期函数-组件创建期间的4个钩子函数
生命周期钩子=生命周期函数=生命周期事件
生命周期函数-组件运行和销毁阶段的钩子函数
vue-resource发起get、post、jsonp请求
<template>
<div>
<input type="button" value="get请求" @click="getInfo">
<input type="button" value="post请求" @click="postInfo">
<input type="button" value="jsonp请求" @click="jsonpInfo">
</div>
</template>
<script>
export default {
// name: 'HelloWorld',
data() {
return {}
},
methods: {
getInfo() {
this.$http.get('http://vue.studyit.io/api/getlunbo').then(result=> {
console.log(result.body)
})
},
postInfo(){
//手动发起的post请求,默认没有表单格式,所以有点服务器处理不了
//通过post方法第三个参数{emulateJSON:true}设置提交表单格式
this.$http.post('http://vue.studyit.io/api/post',{},{emulateJSON:true}).then(result=>{
console.log(result.body)
})
},
jsonpInfo(){
this.$http.jsonp('http://vue.studyit.io/api/jasonp').then(result=>{
console.log(result.body)
})
},
filters: {},
directives: {}
}
</script>