vivo-ui
Version:
vivo ui component lib for vue
77 lines (73 loc) • 2.35 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
(function () {
var scale = 1
var meta = document.querySelector('meta[name=viewport]')
!meta && (meta = document.createElement('meta'))
meta.setAttribute('name', 'viewport')
meta.setAttribute('content', 'width=device-width,initial-scale=' + scale + ',maximum-scale=' + scale + ',minimum-scale=' + scale + ',user-scalable=no')
document.head.appendChild(meta)
//设置rem,当调整系统或者浏览器字体大小时,html元素的默认字体大小也会相应变化
function setRem () {
document.documentElement.style.fontSize = '100%'
originalHtmlFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize)
document.documentElement.style.fontSize = document.documentElement.clientWidth * 1000 / (108 * originalHtmlFontSize) + '%'
}
setRem()
window.addEventListener('resize', setRem)
}())
</script>
<script src="https://cdn.bootcss.com/vue/2.5.16/vue.js"></script>
<script src="../../dist/lib.js"></script>
</head>
<body>
<div id="content">
<button @click="close">关闭所有</button>
<button @click="show">显示toast</button>
<button @click="pluginShow">以插件形式显示toast</button>
<toast ref="toast" :time="time" :position="position">
{{text}}
</toast>
</div>
<script>
//安装插件
Vue.use(VUI.pluginToast)
VUI.toolType('responsive')
var vm = new Vue({
el: '#content',
data: {
time: 1000,
position: 'center',
text: 'toast文本'
},
methods: {
show() {
this.time = 3000 * Math.random() + 10000
this.position = Math.random() > 0.5 ? 'top' : 'bottom'
this.text = Date.now()
this.$refs.toast.show()
},
pluginShow: function () {
this.$vui.toast.show({
slot: '<em>这是插件显示的toast</em><p>段落</p>',
time: 1000 * Math.random() + 3000,
position: Math.random() > 0.5 ? 'center' : 'bottom',
single: false,
className: 'my-toast'
})
},
close() {
this.$vui.toast.hide()
}
},
components: {
Toast: VUI.Toast
}
})
</script>
</body>
</html>