TypeScript ---- 初探
import axios from 'axios';
const url = `http://jsonplaceholder.typicode.com/todos/1`;
//定义接口
interface Todo {
id :number,
title:string,
completed: boolean,
};
axios.get(url).then(res =>{
let todo = res.data as Todo;
const id = todo.id;
const title = todo.title;
const completed = todo.completed;
toDofs(id, title, completed);
});
const toDofs = (id : number, title : string, completed : boolean) =>{
console.log(
`todo的id是:${id};
todo的标题:${title};
是否完成任务:${completed};
`
);