学习vue,在网上看到5个小实例,很受用。拿过来和大家一起分享,都是比较常见,基础的功能。

1、利用vue实现导航功能

<!DOCTYPE html>
<html lang="zh"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta http-equiv="X-UA-Compatible" content="ie=edge" /><title>vue完成导航功能</title><style>* {margin: 0;padding: 0;}body {font: 15px/1.3 'Open Sans', sans-serif;color: #5e5b64;text-align: center;}a,a:visited {outline: none;color: #389dc1;}a:hover {text-decoration: none;}section,footer,header,aside,nav {display: block;}/*-------------------------The menu
--------------------------*/nav {display: inline-block;margin: 60px auto 45px;background-color: #5597b4;box-shadow: 0 1px 1px #ccc;border-radius: 2px;}nav a {display: inline-block;padding: 18px 30px;color: #fff !important;font-weight: bold;font-size: 16px;text-decoration: none !important;line-height: 1;text-transform: uppercase;background-color: transparent;-webkit-transition: background-color 0.25s;-moz-transition: background-color 0.25s;transition: background-color 0.25s;}nav a:first-child {border-radius: 2px 0 0 2px;}nav a:last-child {border-radius: 0 2px 2px 0;}nav.home .home,nav.projects .projects,nav.services .services,nav.contact .contact {background-color: #e35885;}p {font-size: 22px;font-weight: bold;color: #7d9098;}p b {color: #ffffff;display: inline-block;padding: 5px 10px;background-color: #c4d7e0;border-radius: 2px;text-transform: uppercase;font-size: 18px;}</style></head><body><div id="main"><!-- The navigation menu will get the value of the "active" variable as a class. --><!-- To stops the page from jumping when a link is clicked we use the "prevent" modifier (short for preventDefault). --><nav v-bind:class="active" v-on:click.prevent><!-- When a link in the menu is clicked, we call the makeActive method, defined in the JavaScript Vue instance. It will change the value of "active". --><a href="#" class="home" v-on:click="makeActive('home')">Home</a><a href="#" class="projects" v-on:click="makeActive('projects')">Projects</a><a href="#" class="services" v-on:click="makeActive('services')">Services</a><a href="#" class="contact" v-on:click="makeActive('contact')">Contact</a></nav><!-- The mustache expression will be replaced with the value of "active".It will automatically update to reflect any changes. --><p>You chose <b>{{active}}</b></p></div><script src="http://cdnjs.cloudflare.com/ajax/libs/vue/1.0.16/vue.js"></script><script>// Creating a new Vue instance and pass in an options object.var demo = new Vue({// A DOM element to mount our view model.el: '#main',// This is the model.// Define properties and give them initial values.data: {active: 'home'},// Functions we will be using.methods: {makeActive: function(item) {// When a model is changed, the view will be automatically updated.this.active = item;}}});</script></body></html>

  2、利用vue实现编辑器效果

<!DOCTYPE html>
<html lang="zh">
<head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta http-equiv="X-UA-Compatible" content="ie=edge" /><title>vue 实现的内在编辑器</title><style>/* Hide un-compiled mustache bindings
until the Vue instance is ready */[v-cloak] {display: none;
}*{margin:0;padding:0;
}body{font:15px/1.3 'Open Sans', sans-serif;color: #5e5b64;text-align:center;
}a, a:visited {outline:none;color:#389dc1;
}a:hover{text-decoration:none;
}section, footer, header, aside, nav{display: block;
}/*-------------------------The edit tooltip
--------------------------*/.tooltip{background-color:#5c9bb7;background-image:-webkit-linear-gradient(top, #5c9bb7, #5392ad);background-image:-moz-linear-gradient(top, #5c9bb7, #5392ad);background-image:linear-gradient(top, #5c9bb7, #5392ad);box-shadow: 0 1px 1px #ccc;border-radius:3px;width: 290px;padding: 10px;position: absolute;left:50%;margin-left:-150px;top: 80px;
}.tooltip:after{/* The tip of the tooltip */content:'';position:absolute;border:6px solid #5190ac;border-color:#5190ac transparent transparent;width:0;height:0;bottom:-12px;left:50%;margin-left:-6px;
}.tooltip input{border: none;width: 100%;line-height: 34px;border-radius: 3px;box-shadow: 0 2px 6px #bbb inset;text-align: center;font-size: 16px;font-family: inherit;color: #8d9395;font-weight: bold;outline: none;
}p{font-size:22px;font-weight:bold;color:#6d8088;height: 30px;cursor:default;
}p b{color:#ffffff;display:inline-block;padding:5px 10px;background-color:#c4d7e0;border-radius:2px;text-transform:uppercase;font-size:18px;
}p:before{content:'✎';display:inline-block;margin-right:5px;font-weight:normal;vertical-align: text-bottom;
}#main{height:300px;position:relative;padding-top: 150px;
}</style>
</head>
<body><!-- v-cloak hides any un-compiled data bindings until the Vue instance is ready. -->
<!-- When the element is clicked the hideTooltp() method is called. --><div id="main" v-cloak v-on:click="hideTooltip" ><!-- This is the tooltip. v-on:clock.stop is an event handler for clicks, with a modifier that stops event propagation.v-if makes sure the tooltip is shown only when the "showtooltip" variable is truthful --><div class="tooltip" v-on:click.stop v-if="show_tooltip"><!-- v-model binds the contents of the text field with the "text_content" model.Any changes to the text field will automatically update the value, andall other bindings on the page that depend on it.  --><input type="text" v-model="text_content" /></div><!-- When the paragraph is clicked, call the "toggleTooltip" method and stop event propagation. --><!-- The mustache expression will be replaced with the value of "text_content".It will automatically update to reflect any changes to that variable. --><p v-on:click.stop="toggleTooltip">{{text_content}}</p></div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/vue/1.0.16/vue.js"></script>
<script>// Creating a new Vue instance and pass in an options object.
var demo = new Vue({// A DOM element to mount our view model.el: '#main',// Define properties and give them initial values.data: {show_tooltip: false,text_content: 'Edit me.'},// Functions we will be using.methods: {hideTooltip: function(){// When a model is changed, the view will be automatically updated.this.show_tooltip = false;},toggleTooltip: function(){this.show_tooltip = !this.show_tooltip;}}
})
</script>
</body>
</html>

  3、利用vue实现表单提交,自动计算金额的效果

<!DOCTYPE html>
<html lang="zh">
<head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta http-equiv="X-UA-Compatible" content="ie=edge" /><title>vue 实现提交表单</title>
</head>
<style>   @import url(https://fonts.googleapis.com/css?family=Cookie);/* Hide un-compiled mustache bindings
until the Vue instance is ready */[v-cloak] {display: none;
}*{margin:0;padding:0;
}body{font:15px/1.3 'Open Sans', sans-serif;color: #5e5b64;text-align:center;
}a, a:visited {outline:none;color:#389dc1;
}a:hover{text-decoration:none;
}section, footer, header, aside, nav{display: block;
}/*-------------------------The order form
--------------------------*/form{background-color: #61a1bc;border-radius: 2px;box-shadow: 0 1px 1px #ccc;width: 400px;padding: 35px 60px;margin: 50px auto;
}form h1{color:#fff;font-size:64px;font-family:'Cookie', cursive;font-weight: normal;line-height:1;text-shadow:0 3px 0 rgba(0,0,0,0.1);
}form ul{list-style:none;color:#fff;font-size:20px;font-weight:bold;text-align: left;margin:20px 0 15px;
}form ul li{padding:20px 30px;background-color:#e35885;margin-bottom:8px;box-shadow:0 1px 1px rgba(0,0,0,0.1);cursor:pointer;
}form ul li span{float:right;
}form ul li.active{background-color:#8ec16d;
}div.total{border-top:1px solid rgba(255,255,255,0.5);padding:15px 30px;font-size:20px;font-weight:bold;text-align: left;color:#fff;
}div.total span{float:right;
}
</style>
<body><!-- v-cloak hides any un-compiled data bindings until the Vue instance is ready. --><form id="main" v-cloak><h1>Services</h1><ul><!-- Loop through the services array, assign a click handler, and set orremove the "active" css class if needed --><li v-for="service in services" v-on:click="toggleActive(service)" v-bind:class="{ 'active': service.active}"><!-- Display the name and price for every entry in the array .Vue.js has a built in currency filter for formatting the price -->{{service.name}} <span>{{service.price | currency}}</span></li></ul><div class="total"><!-- Calculate the total price of all chosen services. Format it as currency. -->Total: <span>{{total() | currency}}</span></div></form>
<script src="http://cdnjs.cloudflare.com/ajax/libs/vue/1.0.16/vue.js"></script>
<script>var demo = new Vue({el: '#main',data: {// Define the model properties. The view will loop// through the services array and genreate a li// element for every one of its items.services: [{name: 'Web Development',price: 300,active:true},{name: 'Design',price: 400,active:false},{name: 'Integration',price: 250,active:false},{name: 'Training',price: 220,active:false}]},methods: {toggleActive: function(s){s.active = !s.active;},total: function(){var total = 0;this.services.forEach(function(s){if (s.active){total+= s.price;}});return total;}}
});
</script>
</body>
</html>

  4、利用vue实现即时搜索的功能

<!DOCTYPE html>
<html lang="zh">
<head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta http-equiv="X-UA-Compatible" content="ie=edge" /><title>vue 实现即时搜素偶的功能</title><style>/* Hide un-compiled mustache bindings
until the Vue instance is ready */[v-cloak] {display: none;
}*{margin:0;padding:0;
}body{font:15px/1.3 'Open Sans', sans-serif;color: #5e5b64;text-align:center;
}a, a:visited {outline:none;color:#389dc1;
}a:hover{text-decoration:none;
}section, footer, header, aside, nav{display: block;
}/*-------------------------The search input
--------------------------*/.bar{background-color:#5c9bb7;background-image:-webkit-linear-gradient(top, #5c9bb7, #5392ad);background-image:-moz-linear-gradient(top, #5c9bb7, #5392ad);background-image:linear-gradient(top, #5c9bb7, #5392ad);box-shadow: 0 1px 1px #ccc;border-radius: 2px;width: 400px;padding: 14px;margin: 45px auto 20px;position:relative;
}.bar input{background:#fff no-repeat 13px 13px;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkU5NEY0RTlFMTA4NzExRTM5RTEzQkFBQzMyRjkyQzVBIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOkU5NEY0RTlGMTA4NzExRTM5RTEzQkFBQzMyRjkyQzVBIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6RTk0RjRFOUMxMDg3MTFFMzlFMTNCQUFDMzJGOTJDNUEiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6RTk0RjRFOUQxMDg3MTFFMzlFMTNCQUFDMzJGOTJDNUEiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz4DjA/RAAABK0lEQVR42pTSQUdEURjG8dOY0TqmPkGmRcqYD9CmzZAWJRHVRIa0iFYtM6uofYaiEW2SRJtEi9YxIklp07ZkWswu0v/wnByve7vm5ee8M+85zz1jbt9Os+WiGkYdYxjCOx5wgFeXUHmtBSzpcCGa+5BJTCjEP+0nKWAT8xqe4ArPGEEVC1hHEbs2oBwdXkM7mj/JLZrad437sCGHOfUtcziutuYu2v8XUFF/4f6vMK/YgAH1HxkBYV60AR31gxkBYd6xAeF3VzMCwvzOBpypX8V4yuFRzX2d2gD/l5yjH4fYQEnzkj4fae5rJulF2sMXVrAsaTWttRFu4Osb+1jEDT71/ZveyhouTch2fINQL9hKefKjuYFfuznXWzXMTabyrvfyIV3M4vhXgAEAUMs7K0J9UJAAAAAASUVORK5CYII=);border: none;width: 100%;line-height: 19px;padding: 11px 0;border-radius: 2px;box-shadow: 0 2px 8px #c4c4c4 inset;text-align: left;font-size: 14px;font-family: inherit;color: #738289;font-weight: bold;outline: none;text-indent: 40px;
}ul{list-style: none;width: 428px;margin: 0 auto;text-align: left;
}ul li{border-bottom: 1px solid #ddd;padding: 10px;overflow: hidden;
}ul li img{width:60px;height:60px;float:left;border:none;
}ul li p{margin-left: 75px;font-weight: bold;padding-top: 12px;color:#6e7a7f;
}</style>
</head>
<body><form id="main" v-cloak><div class="bar"><!-- Create a binding between the searchString model and the text field --><input type="text" v-model="searchString" placeholder="Enter your search terms" /></div><ul><!-- Render a li element for every entry in the items array. Noticethe custom search filter "searchFor". It takes the value of thesearchString model as an argument. --><li v-for="i in articles | searchFor searchString"><a v-bind:href="i.url"><img v-bind:src="i.image" /></a><p>{{i.title}}</p></li></ul></form>
<script src="http://cdnjs.cloudflare.com/ajax/libs/vue/1.0.16/vue.js"></script>
<script>// Define a custom filter called "searchFor". Vue.filter('searchFor', function (value, searchString) {// The first parameter to this function is the data that is to be filtered.// The second is the string we will be searching for.var result = [];if(!searchString){return value;}searchString = searchString.trim().toLowerCase();result = value.filter(function(item){if(item.title.toLowerCase().indexOf(searchString) !== -1){return item;}})// Return an array with the filtered data.return result;})var demo = new Vue({el: '#main',data: {searchString: "",// The data model. These items would normally be requested via AJAX,// but are hardcoded here for simplicity.articles: [{"title": "What You Need To Know About CSS Variables","url": "http://tutorialzine.com/2016/03/what-you-need-to-know-about-css-variables/","image": "http://cdn.tutorialzine.com/wp-content/uploads/2016/03/css-variables-100x100.jpg"},{"title": "Freebie: 4 Great Looking Pricing Tables","url": "http://tutorialzine.com/2016/02/freebie-4-great-looking-pricing-tables/","image": "http://cdn.tutorialzine.com/wp-content/uploads/2016/02/great-looking-pricing-tables-100x100.jpg"},{"title": "20 Interesting JavaScript and CSS Libraries for February 2016","url": "http://tutorialzine.com/2016/02/20-interesting-javascript-and-css-libraries-for-february-2016/","image": "http://cdn.tutorialzine.com/wp-content/uploads/2016/02/interesting-resources-february-100x100.jpg"},{"title": "Quick Tip: The Easiest Way To Make Responsive Headers","url": "http://tutorialzine.com/2016/02/quick-tip-easiest-way-to-make-responsive-headers/","image": "http://cdn.tutorialzine.com/wp-content/uploads/2016/02/quick-tip-responsive-headers-100x100.png"},{"title": "Learn SQL In 20 Minutes","url": "http://tutorialzine.com/2016/01/learn-sql-in-20-minutes/","image": "http://cdn.tutorialzine.com/wp-content/uploads/2016/01/learn-sql-20-minutes-100x100.png"},{"title": "Creating Your First Desktop App With HTML, JS and Electron","url": "http://tutorialzine.com/2015/12/creating-your-first-desktop-app-with-html-js-and-electron/","image": "http://cdn.tutorialzine.com/wp-content/uploads/2015/12/creating-your-first-desktop-app-with-electron-100x100.png"}]}});
</script>
</body>
</html>

  5、利用vue实现交换布局的功能

<!DOCTYPE html>
<html lang="zh">
<head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta http-equiv="X-UA-Compatible" content="ie=edge" /><title>vue 交还布局的功能</title><style>/* Hide un-compiled mustache bindings
until the Vue instance is ready */[v-cloak] {display: none;
}*{margin:0;padding:0;
}body{font:15px/1.3 'Open Sans', sans-serif;color: #5e5b64;text-align:center;
}a, a:visited {outline:none;color:#389dc1;
}a:hover{text-decoration:none;
}section, footer, header, aside, nav{display: block;
}/*-------------------------The search input
--------------------------*/.bar{background-color:#5c9bb7;background-image:-webkit-linear-gradient(top, #5c9bb7, #5392ad);background-image:-moz-linear-gradient(top, #5c9bb7, #5392ad);background-image:linear-gradient(top, #5c9bb7, #5392ad);box-shadow: 0 1px 1px #ccc;border-radius: 2px;width: 580px;padding: 10px;margin: 45px auto 25px;position:relative;text-align:right;line-height: 1;
}.bar a{background:#4987a1 center center no-repeat;width:32px;height:32px;display:inline-block;text-decoration:none !important;margin-right:5px;border-radius:2px;cursor:pointer;
}.bar a.active{background-color:#c14694;
}.bar a.list-icon{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS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jgiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6MERCQzJDMTMxMEJGMTFFM0EwOUZFNjI5OUE0N0I3QjgiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz4MjPshAAAAXklEQVR42mL4h/8I8B6IGaCYKHFGEMnAwCDIAAHvgZgRyiZKnImBQsACxB+hNoDAQyQ5osQZIT4gH1DsBZABH6AB8x/JaQzEig++WPiII7Rxio/GwmCIBYAAAwAwVIzMp1R0aQAAAABJRU5ErkJggg==);
}.bar input{background:#fff no-repeat 13px 13px;border: none;width: 100%;line-height: 19px;padding: 11px 0;border-radius: 2px;box-shadow: 0 2px 8px #c4c4c4 inset;text-align: left;font-size: 14px;font-family: inherit;color: #738289;font-weight: bold;outline: none;text-indent: 40px;
}/*-------------------------List layout
--------------------------*/ul.list{list-style: none;width: 500px;margin: 0 auto;text-align: left;
}ul.list li{border-bottom: 1px solid #ddd;padding: 10px;overflow: hidden;
}ul.list li img{width:120px;height:120px;float:left;border:none;
}ul.list li p{margin-left: 135px;font-weight: bold;color:#6e7a7f;
}/*-------------------------Grid layout
--------------------------*/ul.grid{list-style: none;width: 570px;margin: 0 auto;text-align: left;
}ul.grid li{padding: 2px;float:left;
}ul.grid li img{width:280px;height:280px;object-fit: cover;display:block;border:none;
}</style>
</head>
<body>
<form id="main" v-cloak><div class="bar"><!-- These two buttons switch the layout variable,which causes the correct UL to be shown. --><a class="list-icon" v-bind:class="{ 'active': layout == 'list'}" v-on:click="layout = 'list'"></a><a class="grid-icon" v-bind:class="{ 'active': layout == 'grid'}" v-on:click="layout = 'grid'"></a></div><!-- We have two layouts. We choose which one to show depending on the "layout" binding --><ul v-if="layout == 'grid'" class="grid"><!-- A view with big photos and no text --><li v-for="a in articles"><a v-bind:href="a.url" target="_blank"><img v-bind:src="a.image.large" /></a></li></ul><ul v-if="layout == 'list'" class="list"><!-- A compact view smaller photos and titles --><li v-for="a in articles"><a v-bind:href="a.url" target="_blank"><img v-bind:src="a.image.small" /></a><p>{{a.title}}</p></li></ul>
</form>
<script src="http://cdnjs.cloudflare.com/ajax/libs/vue/1.0.16/vue.js"></script><script>
var demo = new Vue({el: '#main',data: {// The layout mode, possible values are "grid" or "list".layout: 'list',articles: [{"title": "What You Need To Know About CSS Variables","url": "http://tutorialzine.com/2016/03/what-you-need-to-know-about-css-variables/","image": {"large": "http://cdn.tutorialzine.com/wp-content/uploads/2016/03/css-variables.jpg","small": "http://cdn.tutorialzine.com/wp-content/uploads/2016/03/css-variables-150x150.jpg"}},{"title": "Freebie: 4 Great Looking Pricing Tables","url": "http://tutorialzine.com/2016/02/freebie-4-great-looking-pricing-tables/","image": {"large": "http://cdn.tutorialzine.com/wp-content/uploads/2016/02/great-looking-pricing-tables.jpg","small": "http://cdn.tutorialzine.com/wp-content/uploads/2016/02/great-looking-pricing-tables-150x150.jpg"}},{"title": "20 Interesting JavaScript and CSS Libraries for February 2016","url": "http://tutorialzine.com/2016/02/20-interesting-javascript-and-css-libraries-for-february-2016/","image": {"large": "http://cdn.tutorialzine.com/wp-content/uploads/2016/02/interesting-resources-february.jpg","small": "http://cdn.tutorialzine.com/wp-content/uploads/2016/02/interesting-resources-february-150x150.jpg"}},{"title": "Quick Tip: The Easiest Way To Make Responsive Headers","url": "http://tutorialzine.com/2016/02/quick-tip-easiest-way-to-make-responsive-headers/","image": {"large": "http://cdn.tutorialzine.com/wp-content/uploads/2016/02/quick-tip-responsive-headers.png","small": "http://cdn.tutorialzine.com/wp-content/uploads/2016/02/quick-tip-responsive-headers-150x150.png"}},{"title": "Learn SQL In 20 Minutes","url": "http://tutorialzine.com/2016/01/learn-sql-in-20-minutes/","image": {"large": "http://cdn.tutorialzine.com/wp-content/uploads/2016/01/learn-sql-20-minutes.png","small": "http://cdn.tutorialzine.com/wp-content/uploads/2016/01/learn-sql-20-minutes-150x150.png"}},{"title": "Creating Your First Desktop App With HTML, JS and Electron","url": "http://tutorialzine.com/2015/12/creating-your-first-desktop-app-with-html-js-and-electron/","image": {"large": "http://cdn.tutorialzine.com/wp-content/uploads/2015/12/creating-your-first-desktop-app-with-electron.png","small": "http://cdn.tutorialzine.com/wp-content/uploads/2015/12/creating-your-first-desktop-app-with-electron-150x150.png"}}]}
});
</script>
</body>
</html>

  希望大家看完都能够有所收获!

转载于:https://www.cnblogs.com/TigerZhang-home/p/7483588.html

vue的五个小实例解析其基础功能相关推荐

  1. 完爆Facebook/GraphQL,APIJSON全方位对比解析(一)-基础功能

    相关阅读: 完爆Facebook/GraphQL,APIJSON全方位对比解析(二)-权限控制 完爆Facebook/GraphQL,APIJSON全方位对比解析(三)-表关联查询 自APIJSON发 ...

  2. 四十七、Vue路由导航卫视之实例解析

    路由导航卫视可以作为所有路由的拦截器,在这里,可以做一些相应的业务处理,比如拦截一些无权限的访问之类! 1.路由导航卫士 /*** 问题:为什么在这里使用"路由导航卫视"?* 原因 ...

  3. mpvue 微信小程序_使用Vue.js开发微信小程序:开源框架mpvue解析

    戳蓝字"CSDN云计算"关注我们哦! 作者 | 成全 责编 | 阿秃 转自 | 美团技术团队企业博客 前言 mpvue是一款使用Vue.js开发微信小程序的前端框架.使用此框架,开 ...

  4. 用Vue.js开发微信小程序:开源框架mpvue解析

    前言 mpvue 是一款使用 Vue.js 开发微信小程序的前端框架.使用此框架,开发者将得到完整的 Vue.js 开发体验,同时为 H5 和小程序提供了代码复用的能力.如果想将 H5 项目改造为小程 ...

  5. vue+axios+qs序列化 “三步解析”【含demo实例】- 代码篇

    文章目录 qs序列化:是什么?为什么?怎么办?`实例截图参考` 一.`(简单了解)` · `三步解析 ` 序列化是一种用来处理对象流的机制: 对象.文件.数据,有许多不同的格式,很难统一传输和保存 序 ...

  6. h5+js调取相机做取景框_使用Vue.js开发微信小程序:开源框架mpvue解析

    戳蓝字"CSDN云计算"关注我们哦! 作者 | 成全 责编 | 阿秃 转自 | 美团技术团队企业博客 前言 mpvue是一款使用Vue.js开发微信小程序的前端框架.使用此框架,开 ...

  7. 使用Vue.js开发微信小程序:开源框架mpvue解析

    前言 mpvue是一款使用Vue.js开发微信小程序的前端框架.使用此框架,开发者将得到完整的 Vue.js 开发体验,同时为H5和小程序提供了代码复用的能力.如果想将 H5 项目改造为小程序,或开发 ...

  8. vue重构html css,使用vue重构资讯页面的实例代码解析

    从我接手到将这个页面代码重构前,一直都还是使用angular1的代码去做的,需求来了也是用angular去实现:作为一个憧憬新技术的前端,怎么忍受得了现在还在使用这么有历史感的框架,所以,以前就一直在 ...

  9. 五人分鱼python_Python经典五人分鱼代码实例解析

    本篇文章小编给大家分享一下Python经典五人分鱼代码实例解析,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看. A.B.C.D.E 五人在某天夜里合伙去 ...

最新文章

  1. 【PAT (Basic Level) 】1014 福尔摩斯的约会 (20 分)
  2. 前端对div连线_《前端图形学从入门到放弃》003 三维世界
  3. 大学生应当趁早谋划未来
  4. Spring AOP编程问题:下面代码哪里错了?可以考验对Spring AOP的实现机制是否了解的
  5. java gui容器_[Java教程]GUI Panel 容器以及布局管理器
  6. Eclipse引入jar包步骤
  7. sql server 查询本周、本月所有天数的数据
  8. connect to host master port 22: No route to host 问题解决方案
  9. java将乱码转换成中文_转:java中文乱码的解决
  10. LED字体下载,可视化大屏,数据可视化必备
  11. 计算机算法基础_如何自学计算机专业
  12. 天宇优配|医药股反弹受阻 公募乐观态度不改
  13. 如何查看存储过程内容
  14. sed实现key-value变量替换
  15. 程序员遇到人生低谷期怎么做?
  16. Java银行管理系统
  17. 【Linux】git clone报错fatal: unable to access ‘https://github.com/xxx.git/‘: Encountered end of file
  18. 《蔡康永的说话之道》阅读笔记
  19. C++:重载运算符“+”,用于复数加法运算。(如c1+c2,i+c1,c1+i(i为整数))
  20. 简信CRM:全程智能化掌控,解决合同管理痛点

热门文章

  1. vcs import src < ros2.repos 或 vcs import --input ros2.repos src 下载失败或速度慢
  2. 乐视x820android最新版本,乐视MAX2|MIUI10|安卓8.1|最终完美版|极速_最新最全的乐Max2ROM刷机包下载、刷机教程_...
  3. 如何将 Excel 单元格内容按换行符拆分为多列
  4. 上海证券交易所-债券品种介绍
  5. 【最新版】VScode C\C++中文路径无法运行问题解决办法
  6. <博弈论> HDU1846
  7. 推荐一款多平台快速开发的前端UI框架 —— uView UI
  8. 【数理统计】05. 充分统计量、点估计及其评价准则
  9. fama french-3 模型个人理解
  10. 70后.net老猿,尚能饭否?