1. 开始前的准备

IDE:VSCode(推荐)或者Sublime Text

前导技术:JavaScript中级

2. 官方提供的product例程

product.html页面代码:

<div id="app">
<ul>
<li v-for="product in products">
<input type="number" v-model.number="product.quantity">
{{ product.name }} <!--使用{{<your expression>}}定义表达式-->
<span v-if="product.quantity === 0"> <!--v-if是vue的条件指令-->
- OUT OF STOCK
</span>
<span v-if="product.quantity < 0 || product.quantity % 1 != 0">
- INVALID NUMBER
</span>
<button @click="product.quantity += 1">
Add
</button>
<button @click="product.quantity -= 1">
Minus
</button>
</li>
</ul>
<h2>Total Inventory: {{ totalProducts }}</h2>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script> <!--引入vue-->
<script>
const app = new Vue({ <!--Vue实例是ViewModel-->
el: '#app', <!--el即element对象,绑定DOM进行View和ViewModel的交互-->
data: {
products: [] <!--定义products数组属性-->
},
computed: {
totalProducts () { <!--totalProducts()是computed对象的属性-->
return this.products.reduce((sum, product) => {
return sum + product.quantity
}, 0)
}
},
created () {
fetch('https://api.myjson.com/bins/clqnb')
.then(response => response.json())
.then(json => {
this.products = json.products
})
}
})
</script>

3. 返回json数据的API

json测试数据:

{
"products":[
{"id":1,"quantity":1,"name":"Compass"},
{"id":0,"quantity":2,"name":"Jacket"},
{"id":3,"quantity":5,"name":"Hiking Socks"},
{"id":4,"quantity":2,"name":"Suntan Lotion"}
]
}

json托管(提供API):http://myjson.com/

注意:此处需能够访问外网的代理服务器!

最新文章

  1. .NET基础拾遗(7)Web Service的开发与应用基础
  2. C#定义类型转化 及 格式化字符串
  3. Windows群集安装
  4. css的计数器
  5. union 中可以存储的是不带构造函数的类对象
  6. 你不知道的JavaScript(作用域和闭包)
  7. 【转】silverlight 跨域访问
  8. 介绍Foundation框架
  9. mysql 从一个表中查数据,插入另一个表
  10. nodejs的package.json依赖dependencies中 ^ 和 ~ 的区别
  11. c# webapi上传、读取、删除图片
  12. OO第二单元单元总结
  13. macbook air 2012 mid 安装 windows10 双系统遇到错误 no bootable device insert boot disk and press any key
  14. Python爬虫【四】Scrapy+Cookies池抓取新浪微博
  15. vue实践中的狗血事件之:mock数据引发的血坑
  16. hdu 5784 How Many Triangles 计算几何,平面有多少个锐角三角形
  17. java JDK JRE 1.6,1.7,1.8各个版本版本下载链接
  18. Python高阶函数(Map、Reduce、Filter)
  19. Guava学习笔记:Preconditions优雅的检验参数(java)
  20. mongodb/python3.6/mysql的安装

热门文章

  1. Homebrew学习(七)之你应该定期更新 Homebrew
  2. 企业面试题|最常问的MySQL面试题集合(一)
  3. 我所不知的JS
  4. GDAL支持中文路径和Shp文件中文属性写入
  5. nginx.conf laravel 配置
  6. RHEL6本地YUM源配置
  7. boost多线程编译出错
  8. Java并发编程实战 第3章 对象的共享
  9. 曝郭盛华公司30万美元收购Acn.ai域名,揭秘人工智能布局下的巨头们
  10. Windows 2012 R2 DataCenter服务器 重启之后,其他加域电脑无法访问域账户