news-detail-mobile.js 991 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import language from "./common/language.js";
  2. import Service from "./common/service.js";
  3. new Vue({
  4. el: "#app",
  5. data: {
  6. info: {},
  7. },
  8. mounted() {
  9. const id = location.href.split("?id=")[1];
  10. this.getDetail(id);
  11. },
  12. methods: {
  13. text(val) {
  14. return language[val][localStorage.getItem("language")];
  15. },
  16. lan_key(val) {
  17. return `${val}${localStorage.getItem("language") == "en" ? "_en" : ""}`;
  18. },
  19. getDetail(id) {
  20. Service.get_news_detail({ id })
  21. .then((res) => {
  22. this.info = res;
  23. })
  24. .catch((err) => {
  25. console.log(err);
  26. });
  27. },
  28. downloadFile() {
  29. const a = document.createElement("a");
  30. a.href = Service.baseURL + this.info.url;
  31. a.download = decodeURI(this.info[this.lan_key("url_name")] + ".docx");
  32. document.body.appendChild(a);
  33. a.click();
  34. document.body.removeChild(a); // 下载完移除元素
  35. },
  36. back() {
  37. history.go(-1);
  38. },
  39. },
  40. });