【发布时间】:2018-11-11 13:13:04
【问题描述】:
如何从url获取json数据,并保存到TypeScript的const变量中?
const data = (get json from url);
输出:
data = [
{
"name": "Peter",
"age": "20"
},
{
"name": "John",
"age": "25"
}
];
【问题讨论】:
-
据我所知,
const变量在初始化后无法更改。你需要使用var -
const变量的内部状态在 TypeScript 中仍然可以修改。 typescriptlang.org/docs/handbook/variable-declarations.html -
如引用,
const is an augmentation of let in that it prevents re-assignment to a variable -
@mast3rd3mon
const numLivesForCat = 9; const kitty = { name: "Aurora", numLives: numLivesForCat, } // Error kitty = { name: "Danielle", numLives: numLivesForCat }; // all "okay" kitty.name = "Rory"; kitty.name = "Kitty"; kitty.name = "Cat"; kitty.numLives--; -
也许是这样,但这不是你想要做的
标签: javascript json typescript ecmascript-6