Comments.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <div class="vcomment" v-if="data.comments === 'true'">
  3. <div id="vcomments" key="this_key"></div>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. this_key: ''
  11. }
  12. },
  13. created() {
  14. this.createValine()
  15. },
  16. computed: {
  17. data() {
  18. let arr_1 = this.$page.frontmatter;
  19. let str_1 = '';
  20. for (let i in arr_1) {
  21. str_1 += arr_1[i];
  22. }
  23. let arr_2 = str_1.split(' ');
  24. let obj = {};
  25. for (let i in arr_2) {
  26. let str_arr = str_1.split(' ')[i].split(':');
  27. obj[str_arr[0]] = str_arr[1]
  28. }
  29. return obj
  30. },
  31. },
  32. mounted: function () {
  33. },
  34. methods: {
  35. createValine() {
  36. this.$nextTick(() => {
  37. const Valine = require('valine');
  38. // window.AV = require('leancloud-storage');
  39. const valine = new Valine({
  40. el: '#vcomments',
  41. appId: 'O2bEd2bFE0R0IEE35j9sHGhd-gzGzoHsz',
  42. appKey: 'fF4QkBG5GPghnvV7nqclEqty',
  43. notify: false,
  44. verify: false,
  45. visitor: true,
  46. avatar: 'vBPlRNwUOJlHqfmoSAmXz5Qk',
  47. path: window.location.pathname,
  48. placeholder: '欢迎留言与我分享您的想法...',
  49. });
  50. // this.valineRefresh = false
  51. })
  52. }
  53. },
  54. watch: {
  55. '$route'(to, from) {
  56. if (to.path !== from.path) {
  57. setTimeout(() => {
  58. //重新刷新valine
  59. this.createValine();
  60. this.this_key = Date.parse(new Date()) / 1000
  61. }, 180)
  62. }
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="stylus" rel="stylesheet/stylus">
  68. #vcomments {
  69. max-width 740px
  70. padding 10px
  71. display block;
  72. margin-left auto;
  73. margin-right auto;
  74. }
  75. </style>