怎么在VUE頁面中加載外部HTML

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)怎么在VUE頁面中加載外部HTML,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

成都創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的寶雞網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

1.HtmlPanel.vue文件

<template>
 <div>
  <mu-circular-progress :size="40" v-if="loading"/>
  <div v-html="html"></div>
 </div>
</template>
<style>

</style>
<script>
 export default{
  // 使用時(shí)請使用 :url.sync=""傳值
  props: {
   url: {
    required: true
   }
  },
  data () {
   return {
    loading: false,
    html: ''
   }
  },
  watch: {
   url (value) {
    this.load(value)
   }
  },
  mounted () {
   this.load(this.url)
  },
  methods: {
   load (url) {
    if (url && url.length > 0) {
     // 加載中
     this.loading = true
     let param = {
      accept: 'text/html, text/plain'
     }
     this.$http.get(url, param).then((response) => {
      this.loading = false
      // 處理HTML顯示
      this.html = response.data
     }).catch(() => {
      this.loading = false
      this.html = '加載失敗'
     })
    }
   }
  }
 }
</script>

htmlViewSample.vue

<template>
 <div>
  <v-html-panel :url.asyc="url1"></v-html-panel>
  <v-html-panel :url.asyc="url2"></v-html-panel>
 </div>
</template>
<style scoped>
 div{color:red}
</style>
<script>
 export default{
  data () {
   return {
    url1: '',
    url2: ''
   }
  },
  mounted () {
   this.url1 = 'http://file.xxx.com/group1/M00/0C/F5/xxxxxxxx.html'
   this.url2 = 'http://file.xxx.com/group1/M00/0D/3B/yyyyyyy.html'
  },
  methods: {
  }
 }
</script>

上一張效果圖

怎么在VUE頁面中加載外部HTML

注意事項(xiàng):

  • 直接使用axios處理的GET請求,需要處理跨域

  • 外部的css樣式會(huì)作用到顯示的html

  • 同時(shí)加載的外部html里的script也可能會(huì)執(zhí)行,需要按需處理下

  • 外部HTML文件內(nèi)部的相對路徑將不會(huì)被自動(dòng)識(shí)別,絕對路徑可以

NGINX跨域配置:

(Origin如果使用*的話,好像會(huì)出錯(cuò),這里直接使用請求源的地址,如果擔(dān)心安全性的話,可以用if+正則條件判斷下)

location / {
  add_header Access-Control-Allow-Origin $http_origin;
  add_header Access-Control-Allow-Credentials true;
  add_header Access-Control-Allow-Methods GET;

  access_log /data/nginx/logs/fdfs_https.log main;

  ...
}

上述就是小編為大家分享的怎么在VUE頁面中加載外部HTML了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)頁題目:怎么在VUE頁面中加載外部HTML
文章來源:http://muchs.cn/article46/pdpohg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、云服務(wù)器、自適應(yīng)網(wǎng)站、動(dòng)態(tài)網(wǎng)站、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)