import _Message from './MyMessage.vue';
export default{
install(Vue){
let message = null;
Vue.component(_Message.name, _Message);
Vue.prototype.$message1 = {
show,
hide,
info
}
function info(props){
this.show({...props, type: 'danger'});
}
function show(props){
if(!message){
const Message = Vue.extend({
render(h){
return h('my-message', {props});
}
})
message = new Message();
this.vm = message.$mount();
document.body.appendChild(this.vm.$el);
}
}
function hide(){
document.body.removeChild(this.vm.$el);
message.$destroy();
message = null;
this.vm = null;
}
}
}
<template>
<div :class="['app-x']">
<div :class="['app-box', type]" >
<div class="header" >
{{ title }}
<span class="colse" @click="$message1.hide()">X</span>
</div>
<div class="content">
{{ content }}
</div>
</div>
</div>
</template>
<script>
export default {
name: "MyMessage",
props: {
title: {
type: String,
default: 'title'
},
content: {
type: String,
default: 'my is content'
},
type: {
type: String,
default: 'primage',
validator(value) {
return ['primage', 'success', 'warn', 'danger'].includes(value);
}
}
}
}
</script>
<style lang="scss" scoped>
.app-x {
background-color: rgba(0, 0, 0, .5);
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
.app-box{
position: relative;
top: 100px;
left: 50%;
width: 300px;
margin-left: -250px;
color: #fff;
.header{
font-size: 16px;
padding: 10px 15px;
.colse{
float:right;
color: #fff;
cursor: pointer;
}
}
.content{
background-color: #fff;
padding: 50px 15px 15px;
color: #000;
}
&.primage{
background-color: blue;
}
&.success{
background-color:green;
}
&.warn{
background-color: rgb(28, 25, 25);
}
&.danger{
background-color: yellow;
color: #3a3a3a;
}
}
}
</style>
import MyMessage from '@/components/MyUi/MyMessage';
Vue.use(MyMessage);
// this.$message1.show({
// title: '我是提示',
// content: '我是content',
// type : 'success'
// });
this.$message1.info({
title: 'hello word',
content : 'contents内容'
});
import SelectEdit from './SelectEdit'
export default {
data() {
return {
name: ''
}
},
render(h) {
return h(SelectEdit, {
props: {
value: 1,
type: 'on'
},
class: {
'speci-class': true
},
style: {
color: 'red',
fontSize: '14px',
'font-size': '14px'
},
attrs: {
placeholder: '这是给原生html赋值placeholder属性'
},
domProps: {
innerHTML: 'DOM property',
innerText: 'xxxxxxx'
},
on: {
'xxxchange': val => {
this.name = val.name;
},
'click': val => {
this.name = val.name;
},
},
nativeOn: {
click: this.nativeClickHandler
},
directives: [
{
name: 'my-custom-directive',
value: '2',
expression: '1 + 1',
arg: 'foo',
modifiers: {
bar: true
}
}
],
scopedSlots: {
default: props => createElement('span', props.text)
},
slot: 'name-of-slot',
key: 'myKey',
ref: 'myRef',
refInFor: true
}, '这里是显示文本')
}
}