Rewrite about page with Vue

This commit is contained in:
2018-06-22 22:49:59 +03:00
parent f0c83831db
commit 9227d18970
9 changed files with 86 additions and 122 deletions

View 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>

View File

@ -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') });

View File

@ -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;
}
}

View File

@ -1,12 +1,20 @@
@import '../vars';
$button-border-radius: 0.5em;
$button-background-color: #405480;
%button {
display: inline-block;
color: #fff;
background-color: #405480;
background-color: $button-background-color;
padding: 0.6em 1.2em;
border: none;
font-size: 100%;
font-family: inherit;
border-radius: $button-border-radius;
cursor: pointer;
&:hover {
background-color: darken($button-background-color, 10%);
}
}

View File

@ -80,7 +80,6 @@ export default {
</script>
<style lang="scss">
@import '../vars.scss';
@import '../components/button';
.app {

View File

@ -9,5 +9,3 @@ $preferred-width: 700px;
$first-media-step: $preferred-width - 1px;
$mobile-margin: 0.8em;
$button-border-radius: 0.5em;

View File

@ -9,16 +9,6 @@ title: Обо мне
{% block content %}
<section class="about-me js-about-me">
<div class="about-me__content">
<p class="about-me__note" id="about-me-note"></p>
<p class="about-me__links">
<a id="know-better" href="#">Узнать чуть лучше</a>
</p>
</div>
</section>
<div id="app"></div>
{% endblock %}