俗話說,紙上學來終覺淺,絕知此事要躬行,最近兩天學習了下Vue2.0,想作個項目練下手,順便寫個文章方便複習回顧~javascript
再在配置中添加:css
此時項目中就能夠使用jQuery和Bootstrap了html
<template> </template> <script> export default { name: "${NAME}" } </script> <style scoped> </style>
data() { return { books: [ {id: 1, name: '紅樓夢', author: '曹雪芹', price: 32}, {id: 2, name: '水滸傳', author: '施耐庵', price: 30}, {id: 3, name: '三國演義', author: '羅貫中', price: 24}, {id: 4, name: '西遊記', author: '吳承恩', price: 20} ] } }
2.在template標籤中引用bootstrap和數據定義表格vue
<div id="table"> <table class="table table-striped table-bordered"> <thead> <tr> <td>序號</td> <td>書名</td> <td>做者</td> <td>價格</td> </tr> </thead> <tbody> <tr v-for="book in books"> <td>{{ book.id }}</td> <td>{{ book.name }}</td> <td>{{ book.author }}</td> <td>{{ book.price }}</td> </tr> </tbody> </table> </div>
3.在main.js中引入組件,並將組件填充到Vue實例中java
// 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 App from './App' //導入jquery和bootstrap import 'jquery/dist/jquery.min' import 'bootstrap/dist/js/bootstrap.min.js' import 'bootstrap/dist/css/bootstrap.min.css' import myTable from './components/MyTable' Vue.config.productionTip = false /* eslint-disable no-new */ new Vue({ el: '#app', components: { App,myTable }, template: '<myTable/>' })
4.稍微調整樣式後,瀏覽器顯示結果如圖:jquery