.wxml
<editor id="editor" class="item-content ql-container" placeholder="请输入新闻内容" bindstatuschange="onStatusChange" bindready="onEditorReady" bindinput="onInput" bindblur="onBlur">
</editor>
.js
1、注册editor
onEditorReady() {
const that = this
wx.createSelectorQuery().select('#editor').context(function (res) {
that.oneEditor = res.context;
}).exec()
},
1、注册editor
onEditorReady() {
const that = this
wx.createSelectorQuery().select('#editor').context(function (res) {
that.oneEditor = res.context;
}).exec()
},
1、初始化一个实例
onEditorReady() {
const that = this
wx.createSelectorQuery().select('#editor').context(function (res) {
that.oneEditor = res.context;
}).exec()
},
2、失去焦点后收起键盘
onBlur(e) {
this.oneEditor.blur()
},
3、获取输入的总内容
getContent() {
let that = this;
this.oneEditor.getContents({
success: (res) => {
that.setData({
content: res.html
})
}
})
},
4、获取每次输入后的内容
onInput(e) {
this.setData({
content: e.detail.html
})
},
tip:3、4选一种就可以
5、回显
wx.createSelectorQuery().select('#editor').context(function (r) {
that.oneEditor = r.context;
that.oneEditor.setContents({
'html': res.content,
});
}).exec()
.wxss
.item-content {
flex: 1;
text-align: left;
color: #222222;
font-size: 32rpx;
}
.ql-container {
box-sizing: border-box;
width: 100%;
min-height: 150rpx;
font-size: 16px;
overflow: auto;
padding: 10px 10px 20px 10px;
font-size: 32rpx;
}