<div id="app" @scroll="letsScroll = true" :class="letsScroll && '_scrolled'">
<template>
<input type="text"
:placeholder="placeholder"
:value="value"
@input="onchange">
<app-transition type="toggleDown">
<div>{{ notify }}</div>
</app-transition>
</template>
<script>
export default {
name: 'app-input',
props: ['type', 'value', 'placeholder'],
computed: {
notify() {
let text = 'Поле может содержать только ';
return ( this.type === 'tel' && text + 'цифры' )
|| ( this.type === 'page' && text + 'латинские буквы, цифры (не менее 6 символов)' )
|| ( this.type === 'name' && text + 'русские и латинские буквы, цифры (не менее 3 символов)' )
},
validation(value) {
return {
tel: (/^[0-9]+$/).test(this.value) || !this.value.length,
page: (/^[a-z0-9]+$/i).test(this.value) && this.value.length > 5,
name: (/^[a-zа-яA-ZА-Я0-9 ]+$/i).test(this.value) && this.value.length > 3
}
}
},
methods: {
onchange(e) {
if ( this.validation[this.type] ) {
this.$emit('input', e.target.value);
}
}
}
}
</script>
<template>
<ul>
<li @click = "currentSorting = 'name'"> byName </li>
<li @click = "currentSorting = 'price'"> byPrice </li>
</ul>
<app-product v-for="product in productsBy"
:key="product.id"
:product="product">
</app-product>
</template>
<script>
import AppProduct from './app-product.vue';
export default {
name: 'products-list',
components: { AppProduct },
data() {
return {
currentSorting: 'name',
products: [ {id: 'sdfsdfsdf}, {id: '121qwqwe'}, {id: '2oo23o'} ]
}
},
computed: {
productsBy: function() {
switch(this.currentSorting) {
case 'name': return this.products
case 'price': return this.products
}
}
}
}
</script>
<product :key="product.id"
v-for="product in $parent.products"
v-model="product">
</product>
<template>
<div class="product" data-product-id="value.id" @click="onChecked" >
<!-- product template -->
</div>
</template>
<style>
.product { /** some thing **/ }
</style>
<script>
export default {
name: 'product',
props: ['value'],
methods: {
onChecked() {
this.$emit('input', this.value.id);
}
}
}
</script>
<router-link tag="li" :to="{ name: 'user', params: { id: user.id } }" :class="$style.dropdown__item">
const router = new VueRouter({
mode: 'history',
linkActiveClass: '_active',
routes: [
{ path: '/users/:id', component: require('./components/Profile.vue'), name: 'user' }
]
});
router.beforeEach((to, from, next) => {
if (from.matched.some(record => record.meta.hasMultimedia)) {
stopAllPlayings();
next();
} else next();
});
const routes = [
{
path: '/funnyCatsVideos',
component: require('./views/funny-cats-videos.vue'),
name: 'videos',
meta: { hasMultimedia: true }
},