Rewrite about page with Vue
This commit is contained in:
		
							
								
								
									
										71
									
								
								source/_assets/about_me/about.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								source/_assets/about_me/about.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
			
		||||
<template>
 | 
			
		||||
    <section class="app">
 | 
			
		||||
        <p class="note">{{ fact }}</p>
 | 
			
		||||
        <button @click.prevent="next" class="button-next">Узнать чуть лучше</button>
 | 
			
		||||
    </section>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import _ from 'underscore';
 | 
			
		||||
import Metrika from '../common/metrika';
 | 
			
		||||
 | 
			
		||||
const NOTES = [
 | 
			
		||||
    'Люблю фильм "Три идиота".',
 | 
			
		||||
    'Люблю кататься на велосипеде.',
 | 
			
		||||
    'Люблю читать фантастические книги.',
 | 
			
		||||
    'Люблю шоколад.',
 | 
			
		||||
    'На день рождения ко мне можно прийти без подарка.',
 | 
			
		||||
    'Не люблю пьяных людей.',
 | 
			
		||||
    'Предпочитаю ходить в кино на 2D-сеансы.',
 | 
			
		||||
    'Проехал на велосипеде 200 километров за день.',
 | 
			
		||||
    'Работаю программистом.',
 | 
			
		||||
    'Хотел бы побывать в горах.',
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
    data() {
 | 
			
		||||
        return {
 | 
			
		||||
            notes: NOTES,
 | 
			
		||||
            shown: [],
 | 
			
		||||
            fact: '',
 | 
			
		||||
        };
 | 
			
		||||
    },
 | 
			
		||||
    mounted() {
 | 
			
		||||
        this.pick();
 | 
			
		||||
    },
 | 
			
		||||
    methods: {
 | 
			
		||||
        next() {
 | 
			
		||||
            this.pick();
 | 
			
		||||
            Metrika.hit(location.href);
 | 
			
		||||
        },
 | 
			
		||||
        pick() {
 | 
			
		||||
            let available = _.difference(this.notes, this.shown);
 | 
			
		||||
            if (_.size(available) === 0) {
 | 
			
		||||
                available = this.notes;
 | 
			
		||||
                this.shown = [];
 | 
			
		||||
            }
 | 
			
		||||
            const fact = _.sample(available);
 | 
			
		||||
            this.shown.push(fact);
 | 
			
		||||
            this.fact = fact;
 | 
			
		||||
        },
 | 
			
		||||
    },
 | 
			
		||||
};
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style lang="scss">
 | 
			
		||||
@import '../components/button';
 | 
			
		||||
.app {
 | 
			
		||||
    text-align: center;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.note {
 | 
			
		||||
    display: block;
 | 
			
		||||
    font-size: 160%;
 | 
			
		||||
    margin: 2em auto;
 | 
			
		||||
    min-height: 3em;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.button-next {
 | 
			
		||||
    @extend %button;
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
@@ -1,61 +1,7 @@
 | 
			
		||||
import $ from 'jquery';
 | 
			
		||||
import _ from 'underscore';
 | 
			
		||||
import Backbone from 'backbone';
 | 
			
		||||
import Metrika from '../common/metrika';
 | 
			
		||||
import './style.scss';
 | 
			
		||||
import Vue from 'vue';
 | 
			
		||||
import About from './about.vue';
 | 
			
		||||
 | 
			
		||||
const PageView = Backbone.View.extend({
 | 
			
		||||
    notes: [
 | 
			
		||||
        'Люблю фильм "Три идиота".',
 | 
			
		||||
        'Люблю кататься на велосипеде.',
 | 
			
		||||
        'Люблю читать фантастические книги.',
 | 
			
		||||
        'Люблю шоколад.',
 | 
			
		||||
        'На день рождения ко мне можно прийти без подарка.',
 | 
			
		||||
        'Не люблю пьяных людей.',
 | 
			
		||||
        'Предпочитаю ходить в кино на 2D-сеансы.',
 | 
			
		||||
        'Проехал на велосипеде 200 километров за день.',
 | 
			
		||||
        'Работаю программистом.',
 | 
			
		||||
        'Хотел бы побывать в горах.',
 | 
			
		||||
    ],
 | 
			
		||||
 | 
			
		||||
    shown: [],
 | 
			
		||||
 | 
			
		||||
    events: {
 | 
			
		||||
        'click #know-better': 'onClickKnowBetter',
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    initialize() {
 | 
			
		||||
        this.render();
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    render() {
 | 
			
		||||
        this.showRandomFact();
 | 
			
		||||
        return this;
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    pickRandomFact() {
 | 
			
		||||
        let available = _.difference(this.notes, this.shown);
 | 
			
		||||
        if (_.size(available) === 0) {
 | 
			
		||||
            available = this.notes;
 | 
			
		||||
            this.shown = [];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const phrase = _.sample(available);
 | 
			
		||||
        this.shown.push(phrase);
 | 
			
		||||
 | 
			
		||||
        return phrase;
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    showRandomFact() {
 | 
			
		||||
        const fact = this.pickRandomFact();
 | 
			
		||||
        this.$('#about-me-note').text(fact);
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    onClickKnowBetter(evt) {
 | 
			
		||||
        evt.preventDefault();
 | 
			
		||||
        this.showRandomFact();
 | 
			
		||||
        Metrika.hit(location.href);
 | 
			
		||||
    },
 | 
			
		||||
new Vue({
 | 
			
		||||
    el: '#app',
 | 
			
		||||
    render: h => h(About),
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
new PageView({ el: $('.js-about-me') });
 | 
			
		||||
 
 | 
			
		||||
@@ -1,31 +0,0 @@
 | 
			
		||||
.about-me {
 | 
			
		||||
    display: flex;
 | 
			
		||||
    align-items: center;
 | 
			
		||||
    justify-content: center;
 | 
			
		||||
 | 
			
		||||
    &__content {
 | 
			
		||||
        margin-top: 4em;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    &__note {
 | 
			
		||||
        text-align: center;
 | 
			
		||||
        font-size: 160%;
 | 
			
		||||
        max-width: 400px;
 | 
			
		||||
        min-height: 3em;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    &__links {
 | 
			
		||||
        padding: 0;
 | 
			
		||||
        margin-top: 2.5em;
 | 
			
		||||
        list-style: none;
 | 
			
		||||
        text-align: center;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    &__link {
 | 
			
		||||
        display: inline-block;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    &__link + &__link {
 | 
			
		||||
        margin-left: 1em;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user