view.js 936 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. Vue.component('vue-easymde', VueEasyMDE.VueEasyMDE)
  2. // 查看消息需要用到的JS
  3. app = new Vue({
  4. el: '#app',
  5. data: {
  6. status: -1,
  7. text: null,
  8. easyMDEOpts: {
  9. toolbar: ['preview'],
  10. renderingConfig: { codeSyntaxHighlighting: true },
  11. },
  12. },
  13. mounted: function() {
  14. // 从URL获取GUID,然后透过POST获取消息
  15. var guid = reg_guid.exec(window.location.href)[0];
  16. axios.post('/api/get-msg', {
  17. guid: guid
  18. }).then(function (response) {
  19. var data = response.data;
  20. app.status = data.status;
  21. app.text = data.text;
  22. }).catch(function (error) {
  23. throw error;
  24. alert('发生错误!')
  25. });
  26. },
  27. watch: {
  28. status: function(status) {
  29. if (status !== 1) return;
  30. // 获取成功,等待装载并设定编辑器状态
  31. this.$nextTick(() => {
  32. var easyMDE = this.$refs.preview.getMDEInstance();
  33. easyMDE.togglePreview();
  34. easyMDE.codemirror.setOption('readOnly', true);
  35. });
  36. }
  37. }
  38. })