add radom btn

add radom btn
This commit is contained in:
a-jie 2019-09-27 08:51:47 +08:00
parent 1854bf23f8
commit 32bf0cfa90
6 changed files with 47 additions and 14 deletions

1
source/.gitignore vendored
View File

@ -1,5 +1,6 @@
.DS_Store .DS_Store
node_modules node_modules
package-lock.json
/dist /dist
# local env files # local env files

View File

@ -9,16 +9,17 @@
<script> <script>
import ppo from 'ppo'; import ppo from 'ppo';
import Vue from 'vue'; import EventBus from '../utils/eventbus';
const bus = new Vue();
export default { export default {
name: 'Btn', name: 'Btn',
props: ['active'], props: ['active', 'index'],
created: function () { created: function () {
bus.$on('BTN_CLICK', id => { EventBus.$on('BTN_CLICK', index => {
if (id !== this.id) { if (index !== this.index) {
this.isActive = false; this.isActive = false;
}else{
this.isActive = true;
} }
}); });
@ -35,7 +36,7 @@ export default {
methods: { methods: {
click() { click() {
this.isActive = true; this.isActive = true;
bus.$emit('BTN_CLICK', this.id); //EventBus.$emit('BTN_CLICK', this.index);
} }
} }
} }

View File

@ -10,9 +10,10 @@
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<ul id="portfolio-flters"> <ul id="portfolio-flters">
<Btn @click.native="tabClick(0)" active=true>Beautiful Style</Btn> <Btn v-for="btn in btns" :key="btn.index" :index="btn.index"
<Btn @click.native="tabClick(1)">Creative Design</Btn> @click.native="tabClick(btn.index)">
<Btn @click.native="tabClick(2)">Electronic Clock</Btn> {{ btn.text }}
</Btn>
</ul> </ul>
</div> </div>
</div> </div>
@ -40,9 +41,18 @@
<script> <script>
import axios from 'axios'; import axios from 'axios';
import yaml from 'js-yaml'; import yaml from 'js-yaml';
import Btn from './Btn.vue' import Btn from './Btn.vue';
import EventBus from '../utils/eventbus';
import { arrShuffle } from '../utils/util';
const PAGES = 9; const PAGES = 6;
let BTNS = [
{ index: 0, text: "Beautiful Style" },
{ index: 1, text: "Creative Design" },
{ index: 2, text: "Electronic Clock" }];
BTNS = arrShuffle(BTNS);
export default { export default {
name: 'Content', name: 'Content',
@ -51,9 +61,10 @@ export default {
}, },
data: function () { data: function () {
return { return {
currentTab: 0, currentTab: BTNS[0].index,
pageNum: 0, pageNum: 0,
data: [], data: [],
btns: BTNS,
get items() { get items() {
const frist = this.pageNum * PAGES; const frist = this.pageNum * PAGES;
const num = frist + PAGES; const num = frist + PAGES;
@ -61,6 +72,7 @@ export default {
return this.allItems ? this.allItems.slice(frist, num) : null; return this.allItems ? this.allItems.slice(frist, num) : null;
}, },
get allItems() { get allItems() {
EventBus.$emit('BTN_CLICK', this.currentTab);
return this.data[this.currentTab] || [] return this.data[this.currentTab] || []
} }
} }

View File

@ -3,7 +3,7 @@
<div class="container"> <div class="container">
<div style="visibility: visible; animation-name: zoomIn;" class="col-md-12 text-center wow zoomIn"> <div style="visibility: visible; animation-name: zoomIn;" class="col-md-12 text-center wow zoomIn">
<div class="footer_copyright"> <div class="footer_copyright">
<p> © Copyright, a-jie All Rights Reserved.</p> <p> © Copyright, anonymous All Rights Reserved.</p>
<div class="credits"> <div class="credits">
WebSite designed by <a href="https://bootstrapmade.com/">BootstrapMade.com</a> WebSite designed by <a href="https://bootstrapmade.com/">BootstrapMade.com</a>
</div> </div>

View File

@ -0,0 +1,4 @@
import Vue from 'vue';
const EventBus = new Vue();
export default EventBus;

15
source/src/utils/util.js Normal file
View File

@ -0,0 +1,15 @@
const arrShuffle = (arr) => {
let len = arr.length;
for (let i = 0; i < len; i++) {
let end = len - 1;
let index = (Math.random() * (end + 1)) >> 0;
let t = arr[end];
arr[end] = arr[index];
arr[index] = t;
}
return arr;
};
export { arrShuffle };