Vue单文件模板实例
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单文件模板实例的更多相关文章
- vue单文件组件实例2:简单单文件组件
Introduce.vue: <template> <div class="intro"> 单位介绍 </div> </templat ...
- vue单文件组件实例1:简单单文件组件
HelloWorld.vue: <template> <div class="hello"> <h1>{{msg}}</h1> ...
- 基于VSCode的vue单文件组件模板设置---一次设置,可爽终生
第一步: 第二步: 第三步: 打开vue.json文件后,如果是初次设置,应该如下图所示,绿色注释部分不用管,注意那两个白色大括号 第四步:在大括号内全部粘贴如下代码,保存即可完成vue模板的设置 & ...
- Vue单文件组件
前面的话 本文将详细介绍Vue单文件组件 概述 在很多 Vue 项目中,使用 Vue.component 来定义全局组件,紧接着用 new Vue({ el: '#container '}) 在每个页 ...
- vue 单文件组件
在很多vue项目中,我们使用vue.component来定义全局组件,紧接着用new Vue({el:'#container'})在每个页面内指定一个容器元素 这种方式在很多中小规模的项目中运作的很好 ...
- 如何手动解析vue单文件并预览?
开头 笔者之前的文章里介绍过一个代码在线编辑预览工具的实现(传送门:快速搭建一个代码在线编辑预览工具),实现了css.html.js的编辑,但是对于demo场景来说,vue单文件也是一个比较好的代码组 ...
- webpack入坑之旅(五)加载vue单文件组件
这是一系列文章,此系列所有的练习都存在了我的github仓库中vue-webpack,在本人有了新的理解与认识之后,会对文章有不定时的更正与更新.下面是目前完成的列表: webpack入坑之旅(一)不 ...
- VUE2 第六天学习--- vue单文件项目构建
阅读目录 VUE2 第六天学习--- vue单文件项目构建 回到顶部 VUE2 第六天学习--- vue单文件项目构建 VUE单文件组件在Vue项目中,然后使用 new Vue({el: '#cont ...
- vue 单文件 样式写了scoped 不能覆盖框架原有样式的解决办法
vue 单文件 样式写了scoped 不能覆盖框架原有样式的解决办法 在vue 里面<style scoped></style> 是为了让样式只影响本身自己组件的样式,不改变全 ...
随机推荐
- [leetcode] 9. Binary Tree Level Order Traversal
跟第七题一样,把最后的输出顺序换一下就行... Given a binary tree, return the level order traversal of its nodes' values. ...
- 纸壳CMS 3.0升级.Net Core 2.1性能大提升
微软发布了.Net Core 2.1正式版,纸壳CMS也在第一时间做了升级,并做了一系列的优化和调整,性能大幅提升,并解决了一些历史遗留问题,添加了一些新功能. Github https://gith ...
- nova 宿主机重启自动恢复虚拟机运行状态
1. 宿主机重启自动恢复虚拟机运行状态 1.1 参数描述与默认值 # Whether to start guests that were running before the host reboote ...
- django系列6--Ajax03 ajax参数
ajax的参数 data: 当前ajax请求要携带的数据,是一个json的object对象,ajax方法会默认的把它编码成某种格式 (urlencoded:?a=1&b=2)发送给服务端;此外 ...
- P5277 【模板】多项式开根(加强版)(bsgs or Cipolla)
题面 传送门 题解 首先你得会多项式开根->这里 其次你得会解形如 \[x^2\equiv a \pmod{p}\] 的方程 这里有两种方法,一个是\(bsgs\)(这里),还有一种是\(Cip ...
- 解决org.apache.lucene.store.AlreadyClosedException: this Directory is closed
在Lucene中,关闭一个IndexWriter时抛出AlreadyClosedException异常: org.apache.lucene.store.AlreadyClosedException: ...
- [CentOS] 7 不执行文件 /etc/rc.d/rc.local
chmod 0755 /etc/rc.local systemctl enable rc-local.service --now systemctl restart rc-local.service
- php实现图片base64编码解码
1.图片的base64编码 /*首先要确定图片的类型,需要安装一个php拓展php_fileinfo 如已安装可以在extension_dir目录下找到php_fileinfo.dll(windows ...
- SP9098 LCS3
题目链接 题意分析 \(olinr\) : 序列自动机+一系列的鬼畜操作 相信我 你们没人能切 \(lzxkj\) : \(2^m+vector+\)暴力二分 跑得比你正解还快 首先一看\(m≤5\) ...
- 50.RocketMQ (quickstart)
要多给下属表功,绝不能抢功. 1.订阅消息 /** * Copyright (C) 2010-2013 Alibaba Group Holding Limited * * Licensed under ...