标签:应用 turn cli one func ret head null axios
<head>
<meta charset="UTF-8">
<title>Title</title>
<!--解决闪烁问题-->
<style>
[v-clock] {
display: none;
}
</style>
</head>
<body>
<div id="vue" v-clock>
<div>{{info.name}}</div>
<div>{{info.address.street}}</div>
<a v-bind:href="info.url">点我</a>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
let vm = new Vue({
el: "#vue",
data: {
info: {
name: null,
address: {
country: null,
city: null,
street: null
},
url: null
}
},
mounted() { //钩子函数
axios.get(‘../data.json‘)
.then(response => (this.info = response.data));
}
});
</script>
</body>
<div id="app">
<p>currentTime1:{{currentTime1()}}</p>
<p>currentTime2:{{currentTime2}}</p>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>
<script>
let vm = new Vue({
el: "#app",
data: {
message: "hello"
},
methods: {
currentTime1: () => {
return Date.now();
}
},
computed: {
currentTime2: () => {
return Date.now();
}
}
});
</script>
使用<slot>元素作为承载分发内容的出口,可以应用在组合组件的场景中
@绑定事件,this.$emit调用外部事件
<div id="app">
<todo>
<todo-title slot="todo-title" :title="title"></todo-title>
<!--v-bind:缩写为:绑定数据,v-on缩写为@绑定事件-->
<todo-items slot="todo-items" v-for="(item, index) in todoItems"
:item="item" :index="index" @remove="removeItem(index)" :key="index"></todo-items>
</todo>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>
<script>
Vue.component("todo", {
template:
‘<div> <slot name="todo-title"></slot> <ul> <slot name="todo-items"></slot> </ul> </div>‘
});
Vue.component("todo-title", {
props: [‘title‘],
template:
‘<div>{{title}}</div>‘
});
Vue.component("todo-items", {
props: [‘item‘, ‘index‘],
template:
‘<li>{{index}}-{{item}}<button @click="remove(index)">删除</button></li>‘,
methods: {
remove: function (index) {
/*click后,进入此函数,通过this.$emit,将参数传递给外部的remove事件*/
this.$emit(‘remove‘, index);
}
}
});
let vm = new Vue({
el: "#app",
data: {
title: ‘书籍列表‘,
todoItems: [‘Java‘, ‘Linux‘, ‘Python‘]
},
methods: {
removeItem: function (index) {
console.log("删除了" + vm.todoItems[index]);
this.todoItems.splice(index, 1);
}
}
});
</script>
标签:应用 turn cli one func ret head null axios
原文地址:https://www.cnblogs.com/xiafrog/p/14392966.html