我對 Vue JS 很陌生。目前,我正在尋找一種呈現(xiàn)服務(wù)器發(fā)送的 HTML 頁面的方法。假設(shè)我有一個節(jié)點(diǎn)路由器“health”,它發(fā)送如下 HTML 文件。res.sendFile('test.html', { root: path.dirname(require.main.filename) + '/public/' });在這種情況下,我可以嘗試訪問該文件并通過 Vue JS 以這種方式呈現(xiàn)它嗎?<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; }) } })})();這段代碼沒有按我的預(yù)期工作。
1 回答

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