

get方式:axios请求数据核心代码
- axios.get("./test.json").then(res => {
- console.log(res)
- //数据在res.data.data.films里
- console.log(res.data.data.films)
- })
完整代码:
- DOCTYPE html>
-
-
-
-
Document -
-
-
-
-
-
- new Vue({
- el:"#box",
- data:{
-
- },
- methods:{
- handleClick(){
- axios.get("./test.json").then(res => {
- console.log(res)
- //数据在res.data.data.films里
- console.log(res.data.data.films)
-
- })
- }
- }
- })
-
结果:

post方式:不用写headers
携带的信息放在第二个参数位置上就可以了,不用写其他的;
- handleClick(){
- axios.post("./test.json","name=yiyi&age=100").then(res => {
- console.log(res)
- //数据在res.data.data.films里
- console.log(res.data.data.films)
-
- })
- }
axios.post("./test.json",{name:"yiyi",age:100})