Typescript 中this的简单使用
在编写一个上传文件的组件的时候, 和之前使用的Javascript不同, this 无法在未声明的情况下使用, 在网上找了一通, 需要在函数里首位声明this
function uploadfile(this: any, e: any): void {
this.name = "hello";
}
用的 Vite + Vue3 + TypeScript 编写的简单上传组件
后端是 Python3 + FastAPI 写的
filename: {{ filename }}
from fastapi import FastAPI, UploadFile, File
from pydantic.types import List
from starlette.responses import JSONResponse, HTMLResponse
app = FastAPI()
@app.post("/upload/")
async def create_upload_files(file: UploadFile = File(...)):
return JSONResponse(
{'filename': file.filename}, headers={"Access-Control-Allow-Origin": "*"}
)