您当前的位置: 首页 >  cmmboy1990

vue 预览 txt

cmmboy1990 发布时间:2021-06-21 15:39:12 ,浏览量:3

vue 预览 txt

1.核心代码



  
    
    {{txt}}

  





export default {
  name: 'Txt',
  data() {
    return {
      isFixedHeight: true,
      txt: '',
      url: 'https://xx.txt',
    }
  },
  methods: {
    //返回键
    onClickLeft() {
      this.$router.go(-1)
    },
    readFile(filePath) {
      // 创建一个新的xhr对象
      let xhr = null, okStatus = document.location.protocol === 'file' ? 0 : 200
      xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP')
      xhr.open('GET', filePath, false)
      xhr.overrideMimeType('text/html;charset=utf-8')
      xhr.send(null)
      return xhr.status === okStatus ? xhr.responseText : null
    }


  },

  created() {
    this.txt = this.readFile(this.url)
  }

}



.word-wrap {
  padding: 15px;

  /*img {*/
  /*  width: 100%;*/
  /*}*/
}



关注
打赏
1688896170
查看更多评论

cmmboy1990

暂无认证

  • 3浏览

    0关注

    131博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0472s