我對 Vue JS 很陌生。目前,我正在尋找一種呈現服務器發送的 HTML 頁面的方法。假設我有一個節點路由器“health”,它發送如下 HTML 文件。res.sendFile('test.html', { root: path.dirname(require.main.filename) + '/public/' });在這種情況下,我可以嘗試訪問該文件并通過 Vue JS 以這種方式呈現它嗎?<div id="app"><div v-html="reactPage"></div></div><script>let sessionId = "";(function() { const app = new Vue({ el: '#app', data: { reactPage: undefined }, created() { fetch('launch/health') .then(response => { this.reactPage = response; }) } })})();這段代碼沒有按我的預期工作。
1 回答

白衣非少年
TA貢獻1155條經驗 獲得超0個贊
是的,這里唯一的問題是fetch語法。嘗試這個:
fetch('launch/health')
.then(response => {
return response.text();
})
.then(data => {
this.reactPage = data;
})
您可以考慮使用axios更簡單的 http 請求。
- 1 回答
- 0 關注
- 130 瀏覽
添加回答
舉報
0/150
提交
取消