(blob)
a tag to download the problem, usually in the a tag with adownload
attribute, it is possible to complete thehref
attribute links to the file to download, but only to the same source file, if it is not the same source, the download attribute will be invalidated.
In the first case, a separate tag to achieve the download, you can use the span tag + click event to simulate the behavior of the a tag.
<span style="color: blue; cursor: pointer" @click="download()"></span>
function download() {
const xhr = new XMLHttpRequest();
("GET", "file path", true);
= "blob";
= function () {
const a = ("a");
= ();
= "_blank";
= "Setting the file name";
();
();
};
();
}
In the second case, it is a whole paragraph of html tagged text, modify the whole paragraph of html to realize that every a tag in it can complete the download operation.
A new Blob object is created, a binary data object that can be used to store and manipulate binary data. The Blob object is used here to store the binary data of a document.
The second parameter is an object that specifies the type and encoding of the Blob object. Here the type of the Blob object is specified as Word document (application/) and the encoding method is UTF-8 (charset=UTF-8).
Blob objects can be used to download or upload Word documents, or to preview Word documents in a browser.
<div v-html="content"></div>
const content = ref()
function setAnodeAttr() {
const html = ('#content')
const aList = ('a')
for (let i = 0; i < ; i++) {
aList[i].setAttribute('style', 'color: blue')
const href = aList[i].getAttribute('href')
const title = aList[i].getAttribute('title')
await (href).then((res) => {
const blob = new Blob([], {
type: 'application/;charset=UTF-8'
})
aList[i].setAttribute('href', (blob))
aList[i].setAttribute('download', title)
})
}
// Get the final Text content use
=
}