view.js 729 B

123456789101112131415161718192021222324252627282930
  1. // 查看消息需要用到的JS
  2. app = new Vue({
  3. el: '#app',
  4. data: {
  5. // 解析GUID需要的正则
  6. guidregEx: /[?a-zA-Z0-9]{8}-[?a-zA-Z0-9]{4}-[?a-zA-Z0-9]{4}-[?a-zA-Z0-9]{4}-[?a-zA-Z0-9]{12}/,
  7. status: -1,
  8. text: null,
  9. },
  10. methods: {
  11. getMsg: function() {
  12. // 从URL获取GUID,然后透过POST获取消息
  13. var guid = this.guidregEx.exec(window.location.href)[0];
  14. axios.post('/api/get-msg', {
  15. guid: guid
  16. }).then(function (response) {
  17. var data = response.data;
  18. app.status = data.status;
  19. app.text = data.text;
  20. console.log(data);
  21. }).catch(function (error) {
  22. throw error;
  23. alert('发生错误!')
  24. });
  25. }
  26. },
  27. mounted: function() {
  28. this.getMsg();// 开始获取消息
  29. }
  30. });