菁英数字科技(猩码)-猩码学苑-专注软件开发人才菁英教育
标题: 李扬敏-20221201-ajax [打印本页]
作者: 王源的李可爱 时间: 2022-12-2 00:37
标题: 李扬敏-20221201-ajax
一.今日学习内容
1. 随机数
Math.floor(Math.random() * (max - min + 1)) + min;
2.axios两种写法
axios.get('').then(res=>{})
axios.post('').then(res=>{})
3.axios对象的写法
Get:
axios({
url: 't',
method: 'get',
// data:,
// params:,
}).then(res => {
})
axios({
url: '',
method: 'get',
params: {
id: id
},
}).then(res => {
console.log(res.data.data);
})
post
axios({
url: '',
method: 'post',
}).then(res => {
console.log(res.data.data);
})
axios({
url: '',
method: 'post',
data: {
id: 463
},
}).then(res => {
console.log(res.data.data);
})
4.图片上传
核心方法:FormData();
let fd = new FormData();
5.跨域
协议,域名,端口,任何一个不相同就是跨域
同源协议:协议,域名,端口,三个都相同,不相同就是跨域
浏览器有同源政策,会阻止ajax跨域访问
同源策略是一种约定,是浏览器的一种安全功能
node.js服务端--自己写接口自己调用--express
解决跨域问题
jsonp
script--src
服务端代理
cors跨域资源共享
vue--proxy:配置跨域相关设置
欢迎光临 菁英数字科技(猩码)-猩码学苑-专注软件开发人才菁英教育 (http://www.xingmaxueyuan.com/) |
Powered by Discuz! X3.4 |