Files
ClassContent/历届学生/18课程/class18_2/项目/练习项目/周志威/vue/index1.html
2024-09-27 02:06:13 +08:00

85 lines
2.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.maopao{
width: 200px;
height: 200px;
background: rebeccapurple;
}
/* 当vue代码尚未被解析时 使页面不显示 性能优化 需要在最外层父容器上加 v-cloak*/
[v-cloak]{
display: none;
}
</style>
</head>
<body>
<div class="app" v-cloak>
<h3>{{text}}</h3>
<ul class="list">
<li v-for="v,i in List" :key="i">{{i}}/{{v.title}}</li>
</ul>
<ul class="cont">
</ul>
<br>
<br>
<!-- 当父元素和子元素同时绑定了事件 可能会产生 "冒泡问题" vue中可以用.stop 组织冒泡 -->
<div class="maopao" @click='fff'>
<h2 @click.stop="zzz">快来点我</h2>
</div>
<ul>
<li v-for="val,key,i in Obj" :key="i"> {{val}} | {{key}}</li>
</ul>
<div v-html="vhtml">
</div>
<!-- v-model 一般用在输入框 可实时获取到输入框内的值 如下 : -->
<input type="text" placeholder="请输入" v-model="userinput">
<span> {{userinput}} </span>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var App = new Vue({
el:'.app',
data:{
text:"hello",
vhtml:"<p>用v-html解析后的结果</p>",
userinput:'',
//v-for 可以遍历数组
List:[
{title:"标题1",
},
{title:"标题2",
},
{title:"标题3",
}
],
//v-for 可以遍历对象
Obj:{
title:"aaa",
cont:"aaabbbccc"
}
},
methods: {
fff(){
alert("这是父级元素")
},
zzz(){
alert("这是子级元素")
}
}
})
</script>
</html>