[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>Vue.js
Vue.js的官方文档中是这样介绍它的:简单小巧的核心,渐进式技术栈,足以应付任何规模的应用。
简单小巧是指Vue.js压缩后仅有17KB。所谓渐进式(Progressive),就是我们可以一步一步、有阶段性地来使用Vue.js,不必一开始就使用所有的东西。
使用Vue.js可以让Web开发变得简单,同时也颠覆了传统前端开发模式。它提供了现代Web开发中常见的高级功能:
* 解耦视图与数据
* 可复用的组件
* 前端路由
* 状态管理
* 虚拟DOM(Virtual DOM)
<>MVVM模式
与知名前端框架Angular、Ember等一样,Vue.js在设计上也使用MVVM(Model-View-View Model)模式。
MVVM模式是由经典的软件架构MVC衍生来的。当View(视图层)变化时,会自动更新ViewModel(视图模型),反之亦然。View和ViewModel之间通过双向绑定(data-binding)建立联系。
<>Vue.js与JavaScript和jQuery的不同之处
在我们使用JavaScript或jQuery时,做的最多的事情就是操作DOM、绑定事件等这些。比如在制定DOM中插入一个元素,并给它绑定一个点击事件:
if(showBtn){ var btn = $('<button>Click me</button>'); btn.on('click',function(
){ console.log('Clicked!'); }); $('#app').append(btn); }
这样的操作让我们的视图代码和业务逻辑紧耦合正在一起,随着功能不断增加,直接操作DOM会使得代码越来越难以维护。
而Vue.js通过MVVM的模式拆分为视图与数据两部分,并将其分离。因此,我们只需要关心数据部分即可,DOM的事情Vue会帮我们自动搞定,例如上面的示例可以使用Vue.js改写为:
<body> <div id="myApp"> <button v-if="showBtn" v-on:click="handleClick">Click
me</button> </div> <script> new Vue({ el: '#myApp', data: { showBtn: true },
methods: { handleClick: function(){ console.log('Clicked!'); } } }); </script>
</body>