我想通过提取发送一个帖子请求,但它不起作用.
但是,如果我通过jQuery ajax做到这一点,它就会成功.
我想知道这两种方式的区别,如果我在这里使用fetch有什么问题:
fetch('http://localhost:8888/news',{
method:"post",
data:"code=7&a=8&b=9"
}).then(function(data){
data.json().then(function (json) {
}
Run Code Online (Sandbox Code Playgroud) typescript 源代码undefined!在很多地方使用。例如,在binder.ts 中,从第 261 行到第 271 行:
file = undefined!;
options = undefined!;
languageVersion = undefined!;
parent = undefined!;
container = undefined!;
thisParentContainer = undefined!;
blockScopeContainer = undefined!;
lastContainer = undefined!;
delayedTypeAliases = undefined!;
seenThisKeyword = false;
currentFlow = undefined!;
Run Code Online (Sandbox Code Playgroud)
从打字稿官方文档中,后缀的!意思是“非空断言运算符”,它的定义是:
一个新的!后缀表达式运算符可用于在类型检查器无法得出结论的上下文中断言其操作数为非空和非未定义
所以这种用法undefined!似乎没有意义,因为它断言 undefined 是非未定义的。
是什么意思undefined!,为什么我们这样使用?
在Angualr中看到这些代码是很常见的:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app',
template: '<div *ngFor="let item of data"></div>'
})
export class App {
// we define variable here
data = [1, 2];
tempData = [3, 4]; //temporary data, not involved in view rendering
}
Run Code Online (Sandbox Code Playgroud)
正如我们所看到的,临时变量不会涉及视图渲染,但临时变量对于我们的应用程序在临时存储数据的使用中也是必需的.
这样写的怎么样:
import { Component, OnInit } from '@angular/core';
const tempData = [3, 4]; //temporary data, not involved in view rendering
@Component({
selector: 'app',
template: '<div *ngFor="let item of data"></div>'
})
export class App {
// we …Run Code Online (Sandbox Code Playgroud) javascript ×2
typescript ×2
ajax ×1
angular ×1
eslint ×1
fetch-api ×1
html5 ×1
jquery ×1
tslint ×1