JavaScript 实现简易的图片上传按钮

2020-12-22 15:57:57 浏览数 (1)

代码语言:javascript复制
<input
  type="file"
  name="upload"
  @change="fileChange"
>
代码语言:javascript复制
const picture = ref({} as unknown);
const fileChange = (event: Event) => {
  const files = (event.target as HTMLInputElement).files; // DOM.files
  if (files)
    (picture.value as HTMLFrameElement).src = URL.createObjectURL(files[0]);
};

0 人点赞