react 預覽pdf 轉換


function getReader(response){
  return  new Promise(function(resolve,reject){
    response.blob().then( blob => {
      const reader = new FileReader();
      reader.addEventListener("loadend", function() {
              resolve(reader.result)
      });
      reader.readAsDataURL(blob);  
  })
})
}

async function getFileObjfun (response){
  return await getReader(response);
}

在effects中設置一個轉換函數 yield調用上邊轉換

	*getFileObj({payload},{call,put}){
			const data = yield call(getFileObjfun,payload);
			// console.log(data,"xxxx")
			yield put({
				type: 'savePDf',
				payload:data
			})
		},


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM