-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodesource.html
More file actions
99 lines (90 loc) · 2.47 KB
/
codesource.html
File metadata and controls
99 lines (90 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!doctype html>
<html lang="en">
<head>
<style>
.result {
margin-top: 10px;
background-color: #fff;
}
</style>
</head>
<body>
<h1>Hello, world!</h1>
<div id="app">
<h1>Ace editor for Vue.js2.0 Components</h1>
<p>Editor A</p>
<div style="height: 100px">
<editor editor-id="editorA" :content="contentA" v-on:change-content="changeContentA" ></editor>
</div>
<button @click="getcontentA">voir</button>
<!-- <p class="result">{{contentA}}</p> -->
<!-- <p>Editor B</p>
<div style="height: 100px">
<editor editor-id="editorB" :content="contentB" v-on:change-content="changeContentB"></editor>
</div>
<p class="result">{{contentB}}</p> -->
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://rawgit.com/ajaxorg/ace-builds/master/src-min-noconflict/ace.js"></script>
<script>
Vue.component('Editor', {
template: '<div :id="editorId" style="width: 100%; height: 100%;"></div>',
props: ['editorId', 'content', 'lang', 'theme'],
data () {
return {
editor: Object,
beforeContent: ''
}
},
watch: {
'content' (value) {
if (this.beforeContent !== value) {
this.editor.setValue(value, 1)
}
}
},
mounted () {
const lang = this.lang || 'python'
const theme = this.theme || 'ambiance'
this.editor = window.ace.edit(this.editorId)
this.editor.setValue(this.content, 1)
// mode-xxx.js or theme-xxx.jsがある場合のみ有効
this.editor.getSession().setMode(`ace/mode/${lang}`)
this.editor.setTheme(`ace/theme/${theme}`)
this.editor.on('change', () => {
this.beforeContent = this.editor.getValue()
this.$emit('change-content', this.editor.getValue())
})
}
})
const app = new Vue({
el: "#app",
data () {
return {
contentA: 'default content for Editor A',
// contentB: 'default content for Editor B'
}
},
methods: {
reset () {
this.contentA = 'reset content for Editor A'
// this.contentB = 'reset content for Editor B'
},
changeContentA (val) {
if (this.contentA !== val) {
this.contentA = val
}
},
getcontentA(){
console.log(this.contentA)
}
// changeContentB (val) {
// if (this.contentB !== val) {
// this.contentB = val
// }
// }
}
})
</script>
</body>
</html>