
export default {
props: [“msg”],
setup(props) {
const state = reactive({
// myMsg:props.msg
myMsg: inject(“msg”),
});
function Id(id) {
return document.getElementById(id);
}
function changeToop() {
var file = Id(“file”);
if (file.value == “”) {
//设置默认图片
Id(“myimg”).src =
“http://sandbox.runjs.cn/uploads/rs/72/huvtowwn/zanwu.png”;
} else {
preImg(“file”, “myimg”);
}
}
//获取input[file]图片的url Important
function getFileUrl(fileId) {
var url;
var file = Id(fileId);
url = window.URL.createObjectURL(file.files.item(0));
return url;
}
//读取图片后预览
function preImg(fileId, imgId) {
var imgPre = Id(imgId);
imgPre.src = getFileUrl(fileId);
console.log(imgPre.src)
}
const fileUploadFunc = () => {};
return { …toRefs(state), changeToop };
},
};