vue页面展示保留原有格式

vue页面展示保留原有格式


在这里插入图片描述

在这里插入图片描述
这里从后端获取页面内容,如果后端返回的有格式适用,否则需要用到富文本:
https://panjiachen.github.io/vue-element-admin-site/zh/feature/component/rich-editor.html

方法就是:

<div class="tastrule_center" v-html="integralRule"></div>

原本是

<div>{{integralRule}}</div>

现在写到v-html里面保留原来格式,并且再加一个样式class=“tastrule_center”,样式写在style中。而文本域本身都可以保留格式传给后端。

html:

<template>
    <div slot="setting">
      <el-button type="primary" @click="tastruleEdit">编辑</el-button>
    </div>
    <div class="tastrule_title">积分规则</div>
    <div class="tastrule_center" v-html="integralRule"></div>
</template>

数据模型:

data() {
    return {
      id: ""
      integralRule: "", //积分规则
      ruleDialogVisible: false,
      ruleForm: {
        textarea: "", //弹窗
      },
      rules: {
        textarea: [{ required: true, message: "请输入", trigger: "blur" }],
      },
    };
},

created:

created() {
   this.ruleContinuous();
},

methods:

//获取积分规则详情
ruleContinuous() {
  get("/sys/integral/sel").then((res) => {
    if (res.code === 200) {
      this.id = res.data.id;
      this.integralRule = res.data.integralRule;
    }
  });
},
//点击编辑,赋初始值
tastruleEdit() {
  this.ruleForm.textarea = this.integralRule;
  this.ruleDialogVisible = true;
},
//编辑规则
submitForm(ruleForm) {
   this.$refs[ruleForm].validate((valid) => {
     if (valid) {
       let parmas = {
         id: this.id,
         integralRule: this.ruleForm.textarea,
       };
       put("/sys/integral/update", parmas).then((res) => {
         if (res.code === 200) {
           this.$message.success("添加成功!");
           this.addSubCancle();
           this.ruleContinuous();
         } else {
           this.$message.error(res.message);
         }
       });
     }
   });
 },
//清空编辑弹窗
addSubCancle() {
  this.ruleDialogVisible = false;
  this.ruleForm.textarea = "";
},
//点击蒙层清空弹窗
handleClose(done) {
  this.ruleForm.textarea = "";
  done();
},

样式:

<style lang="less" scoped>
	@import "./Tastrule";
	.tastrule_title {
	  display: flex;
	  justify-content: center;
	  align-items: center;
	  font-size: 20px;
	  padding: 10px;
	}
	.tastrule_center {
	  color: #333333;
	  line-height: 30px;
	  white-space: pre-wrap;
	}
</style>
  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值