//接口
// ts原生写接口
function info(info:{name:string}):void{
console.log('name')
}
info({name:'23'})
interface Person{ //接口是一个对象 ,注意是分号 interface
name:string;
age:number;
}
function Person (name:Person): void{
console.log(name)
}
Person({
name:'张珊',
age:12
})
//示例
interface Config{
type:string;
url:string;
data?:string;
dataType:string
}
function ajax(config:Config):void{
let xhr = new XMLHttpRequest()
console.log(xhr)
xhr.open(config.type,config.url,true)
xhr.send(config.data)
xhr.onreadystatechange = function(){
if(xhr.readyState ==4&&xhr.status == 200){
console.log('success')
console.log(JSON.parse(xhr.responseText))
}else{
console.log(xhr.responseText)
}
}
}
let data = {
type:'get',
url:'http://a.itying.com/api/productlist',
data:'',
dataType:'json'
}
ajax(data)