Comments (7)
可以考虑,目前可以通过自定义工具栏来自行实现,欢迎PR。
from vue-simplemde.
不过感觉这个功能由simplemde来实现比较好,#294,simplemde的作者好像也有2.0的计划,就是不知道要什么时候了。。
from vue-simplemde.
这个功能可以有,
from vue-simplemde.
我自己实现了功能,但不知怎么整合进去 🍔
export default {
components: {
markdownEditor
},
computed: {
simplemde () {
return this.$refs.markdownEditor.simplemde
}
},
mount() {
let _this = this;
this.simplemde.codemirror.on('drop', function (editor, e) {
var fileList = e.dataTransfer.files;
if (fileList.length > 1){
_this.$message.error('一次只能上传一张图片');
return false;
}
if(fileList[0].type.indexOf('image') === -1){
_this.$message.error("只能上传图片!");
return false;
}
// placeholder
let placeholder = "![Uploading " + fileList[0]['name'] + "...]()"
editor.replaceRange(placeholder, {
line: editor.getCursor().line,
ch: editor.getCursor().ch
});
var img = new FormData();
img.append('img', fileList[0]);
axios.post('/images/upload', img).then((res) => {
if (res.data["status"] == "success") {
editor.setValue(editor.getValue().replace(tips, "![](" + res.data['uri'] + ")"));
} else {
_this.$message.error(res.data["message"]);
}
})
});
}
}
后端实现(Laravel)
public function store(Request $request)
{
$file = $request->file('img');
if($file->isValid()) {
$image = new Image();
$image->name = $file->getClientOriginalName();
$image->extension = $file->getClientOriginalExtension();
if (!in_array($image->extension, array('jpg', 'jpeg', 'gif', 'png'))) {
return response()->json([
'status' => 'fail',
'message' => 'Invalid image extension we just allow JPG, GIF, PNG, JPEG'
]);
};
$image->mime_type = $file->getMimeType();
$image->path = $file->store('/upload/images');
return response()->json([
'status' => 'success',
'uri' => url('/') . '/' . $image->path
]);
} else {
return response()->json([
'status' => 'fail',
'message' => '文件非法'
]);
}
from vue-simplemde.
@liniu 不好意思,之前没看到,整合具体是要达到什么效果,现在已经实现了什么呢
from vue-simplemde.
用了第三方的库,可以实现黏贴上传
new InlineAttachment.CodeMirror4(simplemde.codemirror,{
uploadUrl: 'http://127.0.0.1:8080/doc/attach/upload',
progressText: '' ,
onFileUploadResponse(xhr) {
//var placeholder=this.settings.progressText;
var result = JSON.parse(xhr.responseText);
var content='![]('+result.data+')';
this.editor.insertValue(content);
}
});
但是细节还要处理,如:progressText是提示 ,上传完将这段提示替换成正式的url.
from vue-simplemde.
还是觉得不适合加在这个库里,有需要的话参考上面的示例先自行实现吧,实在想要加入这个功能的话,可以给simplemde提pr
from vue-simplemde.
Related Issues (20)
- @input event never fire HOT 1
- Editor not working. Showing regular textarea field HOT 2
- @input event not firing HOT 1
- Vue2.6.x导入VueSimplemde时出现报错 xxx is not exported from package HOT 2
- support for emojis
- marked is not a function
- Cannot enable code highlight HOT 1
- Displaying the rendered markdown without going fullscreen.
- Focusing Element needed HOT 1
- 请问是否删除了 vue-simplemde/src/markdown-editor ? HOT 2
- Vetur & typescript: Cannot find module 'vue-simplemde'. Vetur(2307) HOT 1
- modelVal not updating on model change HOT 3
- Changing the config setup in initialise to the spread operator broke in IE HOT 4
- How do you clear the vue-simplemde after axios.post method? HOT 1
- 怎么使用单纯的查看模式 HOT 3
- v-model is broken HOT 4
- Question: customising button bar HOT 1
- Add changelog.md
- vue-simplemde 支持vue3吗 HOT 1
- Updating modelValue from outside of the editor HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-simplemde.