富文本前端后端uniapp端整合

前端:

        <el-row>
          <el-col :span="24">
            <el-form-item label="商品详情3:">
              <ueditor-wrap v-model="formValidate.description" :config="myConfig"  @beforeInit="addCustomDialog"  style="width: 90%;"></ueditor-wrap>
            </el-form-item>
          </el-col>
        </el-row>



<script>

import UeditorWrap from 'vue-ueditor-wrap';
export default {
  components: { UeditorWrap },

  data() {
    return {

      myConfig: {
        autoHeightEnabled: false, // 编辑器不自动被内容撑高
        initialFrameHeight: 500, // 初始容器高度
        initialFrameWidth: '100%', // 初始容器宽度
        UEDITOR_HOME_URL: '/UEditor/',
        serverUrl: ''
      },

  },

  methods: {
    
        
    addCustomDialog () {
      window.UE.registerUI('yshop', function (editor, uiName) {
        let dialog = new window.UE.ui.Dialog({
          iframeUrl: '/yshop/materia/index',
          editor: editor,
          name: uiName,
          title: '上传图片',
          cssRules: 'width:1200px;height:500px;padding:20px;'
        });
        this.dialog = dialog;

        var btn = new window.UE.ui.Button({
          name: 'dialog-button',
          title: '上传图片',
          cssRules: `background-image: url(../../../assets/images/icons.png);background-position: -726px -77px;`,
          onclick: function () {
            dialog.render();
            dialog.open();
          }
        });

        return btn;
      }, 37);
    },
  }



}

</script>

 

后端:

接口拿到字符串直接存入数据库

<p><span style="font-size: 10px;">11111111122555</span><br/></p><p><strong>dddd22</strong></p><p><span style="color: rgb(255, 0, 0); font-size: 24px;"><strong>你好大字啊</strong></span></p><p><br/></p><p><img style="max-width: 100%;" src="https://image.test.cn/5ca081af6183f.jpg"/><img src="https://image.test.cn/5ca04fa9c08ef.jpg"/></p>

uniapp:


      <!-- 商品详情 -->
      <view class="product-intro">
        <text class="title"><text>产品介绍3</text></text>
        <view class="conter" v-html="storeInfo.description"></view>
      </view>






调用后端接口获取到数据后得处理方式:

      getProductDetail(that.id, from)
        .then(res => {
          res.data.storeInfo.description = res.data.storeInfo.description.replace(/\<img/gi, '<img style="max-width:100%;height:auto;"')
          that.$set(that, 'storeInfo', res.data.storeInfo)
          // 给 attr 赋值,将请求回来的规格赋值给 attr
          that.$set(that.attr, 'productAttr', res.data.productAttr)
})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值