-
Notifications
You must be signed in to change notification settings - Fork 33
/
demo.html
85 lines (79 loc) · 1.94 KB
/
demo.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mini Sandbox</title>
</head>
<body style="opacity: 1;">
<style>
</style>
<style>
body {
position: relative;
height: 100%;
overflow: hidden;
margin: 0;
}
#my-sandbox {
box-shadow: 0.8rem 0.8rem 1.4rem #c8d0e7,
-0.2rem -0.2rem 1.8rem #dddfea;
width: 100vw;
height: 100vh;
/* border: 2px solid rgb(19, 121, 255); */
border-radius: 5px;
box-sizing: border-box;
}
</style>
<div id="my-sandbox"></div>
<script src="https://unpkg.com/mini-sandbox@0.3.17"></script>
<!-- <script src="./dist/index.umd.js"></script> -->
<!-- <script src="./dist/vue-loader.js"></script> -->
<!-- <script src="./dist/react-loader.js"></script> -->
<script>
var mp = new MiniSandbox({
el: '#my-sandbox',
files: {
'index.html': {
urlField: 'code',
defaultValue: `<style>
button {
color: red;
}
</style>
<button>测试</button>
<script>
const btn = document.querySelector('button')
btn.addEventListener('click', () => {
alert('click 事件')
})
<\/script>`,
},
'app.js': {
module: 'esm',
defaultValue: `import { getTime } from './utils.js'
const dom = document.querySelector('.box')
setInterval(() => {
dom.innerHTML = '当前时间: ' + getTime()
}, 1000 / 60)`
},
'utils.js': {
module: 'esm',
defaultValue: `const fill = str => ('0' + str).slice(-2)
export const getTime = (x, y) => {
const dt = new Date()
const h = dt.getHours()
const m = dt.getMinutes()
const s = dt.getSeconds()
return \`\${fill(h)}\:\${fill(m)}:\${fill(s)}\`
}`
}
},
defaultConfig: {
height: '100vh',
}
})
</script>
</body>
</html>