Vue是一套用于构建用户界面的渐进式框架。与其它大型框架不同的是,Vue被设计为可以自底向上逐层应用。Vue的核心库只关注视图层,不仅易于上手,还便于与第三方库或既有项目整合。另一方面,当与现代化的工具链以及各种支持类库结合使用时,Vue 也完全能够为复杂的单页应用提供驱动。其官网在这,里面有开发文档。
下面就给大家带来一个使用Vue+HTML+Bootstrap写的一个备忘录
详细代码如下:
<!doctype html>
<html lang="en">
<head>
<title>备忘录</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- 引入Vue JS -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body>
<div id="app" class="container-fluid">
<div class="jumbotron bg-primary text-light">
<h1 class="display-3">{{title}}</h1>
<p class="lead">{{author}} <span class="badge badge-pill badge-danger">{{edition}}
</span></p>
</div>
<!--输入框 -->
<div class="form-group">
<!-- 数据双向绑定 -->
<input type="text"
v-model="input"
class="form-control form-control-lg" placeholder="记录美好生活">
</div>
<!-- 按钮 -->
<button
@click="add"
class="btn btn-primary btn-lg btn-block">记录{{input}}</button>
<!-- 列表 -->
<ul class="list-group mt-3">
<!-- i为索引,e为数据 -->
<li class="list-group-item"
v-for="(e,i) in list">{{i}}|{{e}}
<!-- 删除 -->
<button
@click="remove(e)"
type="button" class="close" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</li>
</ul>
</div>
<!-- js脚本 -->
<script>
//创建Vue 实例
new Vue({
el:'#app',//查找元素
data: {
input:'',//声明输入框变量
title:'Vue实现的备忘录',
author:'旺仔牛奶',
edition:'典藏版',
list:[]
},
methods: {
add:function(){
// this.list.push(this.input);
this.list.unshift(this.input);
this.input='';//点击事件之后清空输入框
},
remove:function(n){
this.list.splice(n,1)//删除数据
}
}
});
</script>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>
打破零评论