editDesc.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <view class="content">
  3. <editor
  4. @ready="onEditorReady"
  5. id="editor"
  6. placeholder="输入个人简介内容"
  7. placeholder-class="placeholder"
  8. class="textarea"
  9. @input="descInput"
  10. :read-only="isReadOnly"
  11. ></editor>
  12. <view class="btn" @click="save()">保存</view>
  13. </view>
  14. </template>
  15. <script>
  16. const app = getApp();
  17. const req = require('../../utils/request.js');
  18. const api = require('../../utils/api.js');
  19. export default {
  20. data() {
  21. return {
  22. id: '',
  23. brief: '',
  24. isReadOnly: true
  25. };
  26. },
  27. onLoad(opt) {
  28. this.id = opt.id;
  29. let pages = getCurrentPages();
  30. let prevPage = pages[pages.length - 2];
  31. this.brief = prevPage.$vm.brief;
  32. },
  33. methods: {
  34. descInput(event) {
  35. this.brief = event.detail.html;
  36. // if (this.brief) {
  37. // this.descLength = event.detail.text.length - 1;
  38. // } else {
  39. // this.descLength = 0;
  40. // }
  41. },
  42. onEditorReady() {
  43. if (this.isEndit) {
  44. return;
  45. }
  46. const that = this;
  47. uni.createSelectorQuery()
  48. .select('#editor')
  49. .context(function(res) {
  50. that.editorCtx = res.context;
  51. that.editorCtx.setContents({
  52. html: that.brief //这里就是设置默认值的地方(html 后面给什么就显示什么)
  53. });
  54. that.isReadOnly = false;
  55. })
  56. .exec();
  57. },
  58. save() {
  59. let pages = getCurrentPages(); //获取所有页面栈实例列表
  60. let prevPage = pages[pages.length - 2]; //上一页页面实例
  61. prevPage.$vm.brief = this.brief;
  62. uni.navigateBack({
  63. //uni.navigateTo跳转的返回,默认1为返回上一级
  64. delta: 1
  65. });
  66. }
  67. }
  68. };
  69. </script>
  70. <style>
  71. @import './editDesc.css';
  72. .ql-editor.ql-blank:before {
  73. /* 此处设置 placeholder 样式 */
  74. color: rgba(204, 204, 204, 1);
  75. font-style: normal;
  76. min-height: 400px;
  77. }
  78. </style>