我正试图在laravel中获得Summernote
与vue的联系,但无法正常工作。
bootstrap.js
中导入summernote js文件require('summernote / dist / summernote-bs4.js');
summernote
中导入app.scss
样式表@import'〜summernote / dist / summernote-bs4.css';
运行npm run watch
在我的组件ready
部分中添加了以下代码
export default {
data: function () {
return {
project: {
title: '',
body: '',
attachment: '',
projectclass: '',
deadline: '',
budget: 0,
user_id: '',
report_type: '',
csrf: document.querySelector('meta[name="csrf-token"]').getAttribute('content'),
},
errors: null
}
},
computed: {
currentUser() {
return this.$store.getters.currentUser;
}
},
methods: {
add() {
this.errors = null;
const errors = validate(Object.assign(this.$data.project, {user_id: this.currentUser.id}));
if(errors) {
this.errors = errors;
return;
}
axios.post('/api/projects/new', Object.assign(this.$data.project, {user_id: this.currentUser.id})).then((response) => {
this.$router.push('/projects')
});
Vue.nextTick(function () {
$('[data-toggle="tooltip"]').tooltip();
})
}
},
ready: function() {
var config = {};
var that = this;
config.minHeight = null;
config.maxHeight = null;
config.toolbar = [
['style', ['bold', 'italic', 'underline', 'clear']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']]
];
config.onBlur = function(e) {
that.body = $('#summernote').code();
};
$('#summernote').summernote(config);
},
watch: {
budget: function(newValue) {
const result = newValue.replace(/\D/g, "")
.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
Vue.nextTick(() => this.budget = result);
},
}
}