惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
腾讯CDC
V
V2EX
Martin Fowler
Martin Fowler
A
About on SuperTechFans
大猫的无限游戏
大猫的无限游戏
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Check Point Blog
博客园 - 【当耐特】
Cisco Talos Blog
Cisco Talos Blog
The Hacker News
The Hacker News
K
Kaspersky official blog
Security Latest
Security Latest
H
Help Net Security
博客园_首页
美团技术团队
Spread Privacy
Spread Privacy
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
G
Google Developers Blog
NISL@THU
NISL@THU
爱范儿
爱范儿
I
Intezer
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
N
News and Events Feed by Topic
P
Privacy International News Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
雷峰网
雷峰网
人人都是产品经理
人人都是产品经理
V
Vulnerabilities – Threatpost
W
WeLiveSecurity
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Hacker News: Ask HN
Hacker News: Ask HN
I
InfoQ
The Cloudflare Blog
F
Full Disclosure
SecWiki News
SecWiki News
宝玉的分享
宝玉的分享
N
Netflix TechBlog - Medium

博客园 - IT-caijw

claude + trae Redis 介绍与 Node.js 使用教程 技术人日常避坑手册:高效工作,少踩坑 AI应用开发-本地大模型部署与API调用实战:LM Studio完整教程 Cursor AI 实用指南:10个具体示例 AI 是搭子不是替代者:我用大模型工具(cursor,trae)编程的一年经验总结 uniapp 闪屏页被拉伸解决方案 9图制作 X-ECharts:Vue项目中数据可视化的终极利器 jsWebControl解决海康视频插件窗口遮挡层级问题 es6划重点 - IT-caijw - 博客园 Promise原理讲解 async+await应用(异步回调解决方案) - IT-caijw - 博客园 echarts 的日常(教学篇) - IT-caijw - 博客园 angularjs 基础 ## HBuilder MUI开发时genymotion模拟器连接Hbuilder vue07-router 路由 vue06-single-file-component vue04-components vue03-directives 指令 vue02-filters-computer
vue05-REST 请求
IT-caijw · 2018-02-25 · via 博客园 - IT-caijw

异步REST

/*
* @Author: caijw
* @Date:   2018-02-23 14:07:30
* @Last Modified by:   caijw
* @Last Modified time: 2018-02-23 15:04:40
*/
const app = new Vue({
	el : '#app',
	data : {
		editFriend : null,
		friends: [],
		newFriend : ''
	},
	methods: {
		addFriend(item){
			var obj = {
				firstname : item,
				lastname : 'cc',
				age : 29
			}
			fetch("http://localhost:3000/users/",{
				body: JSON.stringify(obj),
				method : 'POST',
				headers: {
					'Content-Type' : 'application/json'
				}
			})
			.then(()=>{
				this.fetchFriend();
			})
		},
		deleteFriend(id, i){
			fetch("http://localhost:3000/users/"+id,{
				method : 'DELETE'
			})
			.then(()=>{
				this.friends.splice(i, 1);
			})
		},
		updateFriend(friend){
			fetch("http://localhost:3000/users/" + friend.id,{
				body: JSON.stringify(friend),
				method : 'PUT',
				headers: {
					'Content-Type' : 'application/json'
				}
			})
			.then(()=>{
				this.editFriend = null;
			})
		},
		fetchFriend(){
			fetch('http://localhost:3000/users')
			.then(response => response.json())
			.then((data)=>{
				this.friends = data;
			})
		}
	},
	mounted(){
		this.fetchFriend();
	},
	template : `
		<div>
			add: <input v-on:keyup.13="addFriend(newFriend)" v-model="newFriend"/>
			<li v-for="friend, i in friends">
				<div v-if="editFriend === friend.id">
					<input v-on:keyup.13="updateFriend(friend)" v-model="friend.firstname" />
					<button v-on:click="updateFriend(friend)">save</button>
				</div>
				<div v-else>
					<button v-on:click="editFriend=friend.id">edit</button>
					<button v-on:click="deleteFriend(friend.id, i)">x</button>
					{{friend.firstname}}
				</div>
			</li>
		</div>
	`
})