uniapp(uncloud) 使用生态开发接口详情4(wangeditor 富文本, 云对象, postman 网络请求)

news/2025/2/22 4:23:57/

wangeditor 官网: https://www.wangeditor.com/v4/pages/01-%E5%BC%80%E5%A7%8B%E4%BD%BF%E7%94%A8/01-%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8.html
这里用vue2版本,用wangeditor 4
终端命令: npm i wangeditor --save

  1. 开始使用
    在项目pages => sy_news => add.vue 页面中
<template>
//...<uni-forms-item name="content" label="文章内容" required><div id="div1"></div></uni-forms-item>
// ...
</template>
<script>
import E from 'wangeditor'
let editor = null
// ...
onReady() {this.onWangEdit()
},
methods:{onWangEdit() {editor = new E("#div1")editor.config.zIndex = 0// 失焦时触发的回调函数editor.config.onblur = (newHtml) => {this.formData.content = newHtml}// 将图片保存本地服务器editor.config.customUploadImg = function(resultFiles, insertImgFn) {resultFiles.forEach(item => {let path = URL.createObjectURL(item)let name = item.nameuniCloud.uploadFile({filePath: path,cloudPath: name}).then(res => {console.log("res", res);insertImgFn(res.fileID)})})}editor.create()},// 提交表格submitForm(value) {// 修复(鼠标在富文本内,直接提交)value.content = editor.txt.html();//...}	// ...}// ...
</script>
  1. 运行项目,浏览器中刷新页面,新增页面, 内容变成我们需要的富文本了,
  2. 修改(edit)界面同样的代码, 不过不同是
<uni-forms-item name="content" label="文章内容" required><div id="div1"><div v-html="formData.content"></div></div>
</uni-forms-item>
  1. 上面都是添加数据,接下来进入写接口了,
    项目 => uniCloud-aliyun => 新建函数或者云对象
    在这里插入图片描述
// index.obj.js
const db = uniCloud.database()
module.exports = {_before: function() { // 通用预处理器},async getList() {const res = await db.collection("sy_news").get()let result = {errCode: 0,errMsg: "查询成功",data: res.data}return result},}

4.1 点击demoObj 目录, 右键, 运行本地云对象, 目录下面多一个demoObj.param.js 文件,

getList()

4.2 保存一下, 点击demoObj 目录, 右键, 运行本地云对象, 终端打印的
在这里插入图片描述
5. 如果带参数怎么弄?

// index.obj.js
const db = uniCloud.database()
module.exports = {_before: function() { // 通用预处理器this.params = this.getParams()[0]this.startTime = Date.now()},async getList() {const res = await db.collection("sy_news").get()let result = {errCode: 0,errMsg: "查询成功",data: res.data}return result},async get() {console.log('this.params', this.params);let {num} = this.paramsconst res = await db.collection("sy_product_nav").limit(num).get()let result = {errCode: 0,errMsg: "查询成功",data: res.data}return result},_after(error, result) {if (error) {throw error}result.timeCode = Date.now() - this.startTimereturn result}}
// demoObj.param.js
get({num: 2
})

在运行ok, 这都是本地运行的,
6. 接下来将 demoObj 右键 , 上传部署, 用postman请求数据
6.1 打开 uniCloud Web 控制台
6.2 云函数/云对象 => 函数/对象列表 (找到demoObj, 点击详情)
6.3 点击编辑, 输入 /demoObj
在这里插入图片描述
6.4 确定, 在点击(复制路径),到postman里面,改为post请求,
在这里插入图片描述
7. 如在postman 里面带参数, uniCloud 中 云对象 一个 getHttpInfo 的API

const db = uniCloud.database()
module.exports = {_before: function() { // 通用预处理器this.params = JSON.parse(this.getHttpInfo().body)// this.httpInfo = JSON.parse(this.getHttpInfo().body)this.startTime = Date.now()},async getList() {const res = await db.collection("sy_news").get()let result = {errCode: 0,errMsg: "查询成功",data: res.data}return result},async get() {let {num} = this.paramsconst res = await db.collection("sy_product_nav").limit(num).get()let result = {errCode: 0,errMsg: "查询成功",data: res.data}return result},_after(error, result) {if (error) {throw error}result.timeCode = Date.now() - this.startTimereturn result}}

在这里插入图片描述


http://www.ppmy.cn/news/1163818.html

相关文章

Win10/11下安装WSL并修改WSL默认安装目录到其他盘

我当前在win11下进行以下操作&#xff0c;其它系统版本有问题可以留言 一、安装WSL 前提条件&#xff1a;我们需要保证你的操作系统版本满足 **Windows 10 版本 2004 及更高版本&#xff08;内部版本 19041 及更高版本&#xff09;或 Windows 11 ** 才能使用以下命令。启用适用…

【苍穹外卖 | 项目日记】第七天

前言&#xff1a; 昨天晚上巨难受&#xff0c;学完之后实在不想写项目日记了&#xff0c;所以就偷了一下懒&#xff0c;今天早上补上昨天的项目日记 目录 前言&#xff1a; 今日完结任务&#xff1a; 今日收获&#xff1a; 学习订单支付的接口&#xff1a; 杂项知识点&…

Minio 文件上传(后端处理同文件判断,同一文件秒传)

记录minio 文件上传 MinIO提供多个语言版本SDK的支持&#xff0c;下边找到java版本的文档&#xff1a; 地址&#xff1a;https://docs.min.io/docs/java-client-quickstart-guide.html maven依赖如下&#xff1a; XML <dependency><groupId>io.minio</groupId…

【C++】C++智能指针

​ ​&#x1f4dd;个人主页&#xff1a;Sherry的成长之路 &#x1f3e0;学习社区&#xff1a;Sherry的成长之路&#xff08;个人社区&#xff09; &#x1f4d6;专栏链接&#xff1a;C学习 &#x1f3af;长路漫漫浩浩&#xff0c;万事皆有期待 上一篇博客&#xff1a;【C】C异…

【数据库】通配符进行过滤

通配符进行过滤 通配符 do what&#xff1f;通配符 is which?百分号 % 通配符下划线 _ 通配符方括号 [] 通配符 使用通配符的技巧 How? 通配符 do what&#xff1f; 假设我有一组数据&#xff0c;我需要过滤出 prod_name 中所有包含 “银行” 的字段&#xff1b; SELECT * …

一天吃透Java集合面试八股文

内容摘自我的学习网站&#xff1a;topjavaer.cn 常见的集合有哪些&#xff1f; Java集合类主要由两个接口Collection和Map派生出来的&#xff0c;Collection有三个子接口&#xff1a;List、Set、Queue。 Java集合框架图如下&#xff1a; List代表了有序可重复集合&#xff0c…

十六章:Java8的其它新特性

16.1&#xff1a;Lambda表达式 package com.jiayifeng.java;import org.junit.Test;import java.util.Comparator; import java.util.function.Consumer;/*** author 爱编程的小贾* create 2023-10-19 12:29** 一&#xff1a;Lambda表达式的使用* 1.举例&#xff1a;(o1,…

SIPp使用经验

xml文件&#xff0c;建议<?xml version"1.0" encoding"UTF-8" ?>&#xff0c;不建议ISO-8859-1命令行传key参数 sipp -key contact_port 9999 ...<send retrans"500"><![CDATA[REGISTER sip:[field1]:[remote_port] SIP/2.0Vi…