AddItemComponent.vue

   <template>
<div id="add-item-template">
<div class="input-group">
<input @keyup.enter="addItem" v-model="newItem" placeholder="add shopping list item" type="text" class="form-control">
<span class="input-group-btn">
<button @click="addItem" class="btn btn-default" type="button">Add!</button>
</span>
</div>
</div>
</template> <script>
export default {
props:['items'],
data: function () {
return {
newItem: ''
}
},
methods: {
addItem: function () {
console.log(this.items)
var text; text = this.newItem.trim();
if (text) {
this.items.push({
text: text,
checked: false
});
this.newItem = "";
}
}
}
}
</script>

ChangeTitleComponenet.vue

   <template >
<div id="change-title-template">
<em>Change the title of your shopping list here</em>
<input :value="value" v-on:input="onInput" />
</div>
</template> <script>
export default {
props: ['value'],
methods: {
onInput: function (event) {
this.$emit('input', event.target.value)
}
}
}
</script>

ItemComponent.vue

 <template>
<div id="item-template">
<li :class="{ 'removed': item.checked }">
<div class="checkbox">
<label>
<input type="checkbox" :checked='item.checked' v-on:change="onInput">
<span>
{{ item.text }}</span>
</label>
</div>
</li>
</div>
</template>
<script>
export default {
model: { props: 'checked', event: "change" },
props: ["item",'checked'],
methods: {
onInput() {
this.$emit("change", event.target.checked);
}
}
};
</script> <style scoped>
.removed {
color: gray;
} .removed span {
text-decoration: line-through;
}
</style>

ItemsComponent.vue

   <template id="items-template">
<div id="items-template">
<ul>
<item-component v-model="item.checked" v-for="(item, index) in items" :item="item" :key="index">
</item-component>
</ul>
</div>
</template> <script>
import ItemComponent from "./ItemComponent";
export default {
props: ["items"],
components: {
ItemComponent
}
};
</script> <style scoped>
ul li {
list-style-type: none;
} ul li span {
margin-left: 5px;
}
</style>

App.vue

 <template>
<div id="app" class="container">
<h2>{{ title }}</h2>
<add-item-component :items="items"></add-item-component>
<items-component :items="items"></items-component>
<div class="footer">
<hr/>
<change-title-component v-model="title"></change-title-component>
</div>
</div>
</template> <script>
import AddItemComponent from './components/AddItemComponent'
import ItemsComponent from './components/ItemsComponent'
import ChangeTitleComponent from './components/ChangeTitleComponent'
export default { components:{
AddItemComponent,
ItemsComponent,
ChangeTitleComponent
},
data() {
return {
items: [
{
text: "Bananas",
checked: true
},
{
text: "Apples",
checked: false
}
],
title: "My Shopping List",
newItem: ""
};
}
};
</script> <style>
.container {
width: %;
margin: 20px auto 0px auto;
} .footer {
font-size: .7em;
margin-top: 40vh;
}
</style>

main.js

 // The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import router from './router'
//import ElementUI from 'element-ui'
//import 'element-ui/lib/theme-chalk/index.css'
import App from './App' Vue.config.productionTip = false
//Vue.use(ElementUI) new Vue({
el: "#app",
components:{
App
},
template:"<App />"
});

index.html

 <!DOCTYPE html>
<html> <head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>learn1</title>
</head> <body>
<div id="app"></div> </body> </html>

Vue单文件模板实例的更多相关文章

  1. vue单文件组件实例2:简单单文件组件

    ​ Introduce.vue: <template> <div class="intro"> 单位介绍 </div> </templat ...

  2. vue单文件组件实例1:简单单文件组件

    ​ HelloWorld.vue: <template> <div class="hello"> <h1>{{msg}}</h1> ...

  3. 基于VSCode的vue单文件组件模板设置---一次设置,可爽终生

    第一步: 第二步: 第三步: 打开vue.json文件后,如果是初次设置,应该如下图所示,绿色注释部分不用管,注意那两个白色大括号 第四步:在大括号内全部粘贴如下代码,保存即可完成vue模板的设置 & ...

  4. Vue单文件组件

    前面的话 本文将详细介绍Vue单文件组件 概述 在很多 Vue 项目中,使用 Vue.component 来定义全局组件,紧接着用 new Vue({ el: '#container '}) 在每个页 ...

  5. vue 单文件组件

    在很多vue项目中,我们使用vue.component来定义全局组件,紧接着用new Vue({el:'#container'})在每个页面内指定一个容器元素 这种方式在很多中小规模的项目中运作的很好 ...

  6. 如何手动解析vue单文件并预览?

    开头 笔者之前的文章里介绍过一个代码在线编辑预览工具的实现(传送门:快速搭建一个代码在线编辑预览工具),实现了css.html.js的编辑,但是对于demo场景来说,vue单文件也是一个比较好的代码组 ...

  7. webpack入坑之旅(五)加载vue单文件组件

    这是一系列文章,此系列所有的练习都存在了我的github仓库中vue-webpack,在本人有了新的理解与认识之后,会对文章有不定时的更正与更新.下面是目前完成的列表: webpack入坑之旅(一)不 ...

  8. VUE2 第六天学习--- vue单文件项目构建

    阅读目录 VUE2 第六天学习--- vue单文件项目构建 回到顶部 VUE2 第六天学习--- vue单文件项目构建 VUE单文件组件在Vue项目中,然后使用 new Vue({el: '#cont ...

  9. vue 单文件 样式写了scoped 不能覆盖框架原有样式的解决办法

    vue 单文件 样式写了scoped 不能覆盖框架原有样式的解决办法 在vue 里面<style scoped></style> 是为了让样式只影响本身自己组件的样式,不改变全 ...

随机推荐

  1. delphi中,write和read的用法?什么时候需要用?

    如你所说,在控件或者类的属性中,read 表示 读取,write 则表示设置.比如在类中:TTestClass = (Class)privateFOrderCode:String;publicprop ...

  2. 如何在powerdesign15.1中使用自增列

    点击要设置为自增列的列 右键选择properties(或者按下ALT+enter) 点选红框,再点击Microsoft选项卡, 输入开始值和自增值即可 来自为知笔记(Wiz)

  3. CodeIgniter使用中写的一些文章

    CI的captcha替代类库:  http://www.ifixedbug.com/posts/codeigniter-captcha-library 原生的captcha不是太好用,自己组装一个吧. ...

  4. 利用backgroundwork----递归读取网页源代码,并下载href链接中的文件

    今天闲着没事,研究了一下在线更新程序版本的问题.也是工作中的需要,开始不知道如何下手,各种百度也没有找到自己想要的,因为我的需求比较简单,所以就自己琢磨了一下.讲讲我的需求吧.自己在IIs上发布了一个 ...

  5. 2-初步了解C#-类与对象

    本篇博客对应视频讲解 回顾 我们在第一篇文章中讲了编程中最基本的内容,如输入输出.字符串处理.数字类型计算.分支及循环结构等.无论学习什么语言,这些内容都是相通的. 本篇博客主要演示列表(List)的 ...

  6. [uwp]ImageSource和byte[]相互转换

    最近做一个小app遇到一个问题,到目前还没有比较好的解决方法(可能是我查的资料不够多) 需求如下: 1.把一个Image中的图像保存到字节数组: 2.把字节数组转换为ImageSource,通过Ima ...

  7. 《快学Scala》第二章 控制结构和函数

  8. sqli-labs lession 5 之盲注型SQL入门

    本文作者:Mochazz 如果所查询的用户id在数据库中,可以发现页面显示”You are in”,而不像前4关那样会显示出具体的账号密码. 如果sql语句查询结果不存在,则不会显示”You are ...

  9. verify验证插件的详解

    使用此验证插件,我们只需要新建一个实例对象,同时传入一个json对象就行了,这里我们只传入了两个属性:checkItem和callback.下面的代码解析,我们就按照这个例子来. var verify ...

  10. javascriptdocument load 和document ready的区别

    页面加载完成有两种事件,一是ready , 表示文档结构已经加载完成(貋图片等非文字媒体文件),二是onload 指示页面包含图片等文件在内的所有元素都加载完成.   1.执行时间不同: 从字面的意思 ...