<div id="app">
<my-component v-if="message" :message="message"></my-component>
<div class="actions">
<button @click="update">更新</button>
<button @click="uninstall">卸载</button>
<button @click="install">安装</button>
</div>
</div>
<div class="skip">
<a href="https://codepen.io/collection/DRKGbz/" target="_blank">Vue案例全集</a>
</div>
@import url(https://fonts.googleapis.com/css?family=Montserrat);
$colour:hsla(350,100%,25%,1);
$grey:desaturate($colour,90%);
body {
background:lighten($grey,30%);
background-image:
linear-gradient(40deg,transparentize($grey,0.95),transparentize($colour,0.95)),
linear-gradient(135deg,
lighten($grey,18%) 0%,
lighten($grey,18%) 10%,
lighten($grey,25%) 11%,
lighten($grey,25%) 40%,
lighten($grey,35%) 41%,
lighten($grey,35%) 50%,
lighten($grey,18%) 51%,
lighten($grey,18%) 60%,
lighten($grey,25%) 61%,
lighten($grey,25%) 90%,
lighten($grey,35%) 91%)
;
background-size:7px 7px, 4px 4px;
display: flex;
justify-content: center;
align-items: center;
font-family: montserrat;
}
html,body {
width: 100vw;
height: 100vh;
}
#app {
background: white;
border: 0 none;
border-radius: 3px;
box-shadow: 0 0 15px 1px rgba(0, 0, 0, 0.4);
padding: 20px 30px;
box-sizing: border-box;
text-align: center;
}
.title {
margin: 0 0 25px;
display: inline-block;
border-bottom: 2px solid #69f;
padding-bottom: 5px;
color: #69f;
text-shadow: 1px 1px 0 rgba(#000, .4);
}
button {
color: #454545;
background: transparent;
border: 2px solid #454545;
position: relative;
margin: 1em .5rem;
padding: 0.5em 1em;
transition: all 0.3s ease-in-out;
text-align: center;
font-family: comfortaa;
font-weight: bold;
font-size: 1.2rem;
cursor: pointer;
}
button:before, button:after {
content: '';
display: block;
position: absolute;
border-color: #454545;
box-sizing: border-box;
border-style: solid;
width: 1em;
height: 1em;
transition: all 0.3s ease-in-out;
}
button:before {
top: -6px;
left: -6px;
border-width: 2px 0 0 2px;
z-index: 5;
}
button:after {
bottom: -6px;
right: -6px;
border-width: 0 2px 2px 0;
}
button:hover:before, button:hover:after {
width: calc(100% + 12px);
height: calc(100% + 12px);
border-color: #fff;
}
button:hover {
color: #353535;
background-color: #fff;
}
button:active, button:focus {
outline: none;
}
.skip{
position: fixed;
right: 0;
bottom: 0;
padding: 10px 30px;
background: rgba(0,0,0,.5);
a {
color: #fff;
text-decoration: none;
text-shadow: 1px 1px 0 rgba(0, 0, 0, .15);
}
}
View Compiled
Vue.directive('hello', {
// 只调用一次,指令第一次绑定到元素时调用
bind: function (el) {
console.log(el.parentNode)
console.log('触发bind钩子函数!')
},
// 被绑定元素插入父节点时调用
inserted: function (el) {
console.log(el.parentNode)
console.log('触发inserted钩子函数!')
},
// 所在组件的`VNode`更新时调用,但是可能发生在其子元素的`VNode`更新之前
update: function (el) {
console.log('触发update钩子函数!')
},
// 所在组件的`VNode`及其子元素的`VNode`全部更新时调用
componentUpdated: function (el) {
console.log('触发componentUpdated钩子函数!')
},
// 只调用一次,指令与元素解绑时调用
unbind: function (el) {
console.log('触发unbind钩子函数!')
}
})
let myComponent = {
template: '<h1 v-hello>{{ message }}</h1>',
props: {
message: String
}
}
let app = new Vue({
el: '#app',
data () {
return {
message: 'Hello! 大漠'
}
},
components: {
myComponent: myComponent
},
methods: {
update: function () {
this.message = 'Hi! 大漠'
},
uninstall: function () {
this.message = ''
},
install: function () {
this.message = 'Hello!W3cplus'
}
}
})
View Compiled
This Pen doesn't use any external CSS resources.