<div id="content" class="input-group col-sm-8" style="margin-left: 16%">{$list.content</div>
<textarea style="display: none" id="contents" name="content" placeholder="请输入公告内容">{$list.content}</textarea>

然后就是图片上传代码?首先要在js中配置点东西。?
const E = window.wangEditor
const editor = new E('#content')
// 或者 const editor = new E( document.getElementById('div1') )
const $text1 = $('#contents')
editor.config.onchange = function (html) {
// 第二步,监控变化,同步更新到 textarea
$text1.val(html)
}
// 第一步,初始化 textarea 的值
$text1.val(editor.txt.html())
editor.config.uploadImgServer = "{:url('Upload/uploadall')}"; // 上传图片到服务器
editor.config.uploadFileName = "file"; //文件名称 也就是你在后台接受的 参数值
editor.config.uploadImgHeaders = { //header头信息
'Accept': 'text/x-json'
}
// 将图片大小限制为 3M
editor.config.uploadImgMaxSize = 10 * 1024 * 1024 //默认为5M
editor.config.uploadImgShowBase64 = false; // 使用 base64 保存图片
// editor.customConfig.customAlert = function (info) { //自己设置alert错误信息
// // info 是需要提示的内容
// alert(‘自定义提示:‘ + ‘图片上传失败,请重新上传‘)
// };
editor.config.debug = true; //是否开启Debug 默认为false 建议开启 可以看到错误
// editor.customConfig.debug = location.href.indexOf(‘wangeditor_debug_mode=1‘) > 0; // 同上 二选一
//图片在编辑器中回显
editor.config.uploadImgHooks = {
error: function (xhr, editor) {
alert("2:" + xhr + "请查看你的json格式是否正确,图片并没有上传");
// 图片上传出错时触发 如果是这块报错 就说明文件没有上传上去,直接看自己的json信息。是否正确
// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象
},
fail: function (xhr, editor, result) {
// 如果在这出现的错误 就说明图片上传成功了 但是没有回显在编辑器中,我在这做的是在原有的json 中添加了
// 一个url的key(参数)这个参数在 customInsert也用到
//
alert("1:" + xhr + "请查看你的json格式是否正确,图片上传了,但是并没有回显");
},
success: function (xhr, editor, result) {
//成功 不需要alert 当然你可以使用console.log 查看自己的成功json情况
//console.log(result)
// insertImg(‘https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png‘)
},
customInsert: function (insertImg, result, editor) {
insertImg(result.data.file);
}
};
editor.create()
这些是javascript的配置代码。
起初我也不知道可以这样上传,这小小的功能也困扰了我很久,也使用了很多方法,最后还有这个帮助了我谢谢
https://www.cnblogs.com/wjm956/p/9449147.html
|