const Foo = {
template: `...`,
beforeRouteEnter (to, from, next) {
// вызывается до подтверждения пути, соответствующего этому компоненту.
// НЕ ИМЕЕТ доступа к контексту экземпляра компонента `this`,
// так как к моменту вызова экземпляр ещё не создан!
},
beforeRouteUpdate (to, from, next) {
// вызывается когда маршрут, что рендерит этот компонент изменился,
// но этот компонент будет повторно использован в новом маршруте.
// Например, для маршрута с динамическими параметрами `/foo/:id`, когда мы
// перемещаемся между `/foo/1` и `/foo/2`, экземпляр того же компонента `Foo`
// будет использован повторно, и этот хук будет вызван когда это случится.
// Также имеется доступ в `this` к экземпляру компонента.
},
beforeRouteLeave (to, from, next) {
// вызывается перед переходом от пути, соответствующего текущему компоненту;
// имеет доступ к контексту экземпляра компонента `this`.
}
}
beforeRouteEnter (to, from, next) {
next(vm => {
// экземпляр компонента доступен как `vm`
})
}
export const $axios: AxiosInstance = _axios
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
import Vue from 'vue'
// Full config: https://github.com/axios/axios#request-config
// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
/* eslint-disable */
const config = {
baseURL: process.env.VUE_APP_API,
timeout: 30000,
validateStatus (status: number) {
return status < 500 // Resolve only if the status code is less than 500
}
}
/* eslint-enable */
const _axios: AxiosInstance = axios.create(config)
/* eslint-disable */
// @ts-ignore
_axios.interceptors.request.use(async (config: AxiosRequestConfig): AxiosRequestConfig | Promise<AxiosRequestConfig> => {
return Promise.resolve(config)
}, (error) => {
// Do something with request error
return Promise.reject(error)
}
)
/* eslint-disable */
// Add a response interceptor
_axios.interceptors.response.use((response): Promise<AxiosResponse> | any => {
return response
}, (error) => {
// Do something with response error
return Promise.reject(error)
}
)
class AxiosPlugin {
public install () {
Object.defineProperties(Vue.prototype, {
axios: {
get () {
return _axios
}
},
$axios: {
get () {
return _axios
}
}
})
}
}
const axiosPlugin: AxiosPlugin = new AxiosPlugin()
Vue.use(axiosPlugin)
export default axiosPlugin
export const $axios: AxiosInstance = _axios
model: {
prop: 'selected',
event: 'change'
},
<template>
<v-autocomplete
v-model="selected"
:items="users"
:search-input.sync="usersSearchQuery"
persistent-hint
:label="label"
:rules="rules"
:loading="loading"
>
<template
v-slot:prepend
v-if="visibleIcon && ['lg', 'md'].includes($vuetify.breakpoint.name)"
>
<v-icon class="pl-5 pr-9">mdi-account-tie</v-icon>
</template>
<template v-slot:selection="{ attr, on, item }">
<span>{{ item.first_name }} {{ item.last_name }}</span>
</template>
<template v-slot:item="{ item }">
<v-list-item-avatar
color="indigo"
class="headline font-weight-light white--text"
>
{{ item.first_name.charAt(0) }}
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>{{ item.first_name }} {{ item.last_name }}</v-list-item-title>
<v-list-item-subtitle
v-if="item.role"
v-text="item.role.name"
></v-list-item-subtitle>
</v-list-item-content>
</template>
</v-autocomplete>
</template>
<script lang="ts">
import Vue from 'vue'
import { debounce } from 'vuetify/src/util/helpers'
import { Users } from '@/api/Users'
export default Vue.extend({
name: 'UserAutocomplete',
model: {
prop: 'selected',
event: 'change'
},
props: {
selectedId: {
type: Number,
default: 0
},
search: {
type: String,
default: ''
},
rules: {
type: Array,
default: undefined
},
visibleIcon: {
type: Boolean,
default: false
},
label: {
type: String,
default: ''
}
},
data () {
return {
loading: false,
selectOnce: false,
selected: null,
usersSearchQuery: null,
usersProcessLoading: false,
usersSearchDebounce: debounce((q: string) => {
this.loading = true
new Users().findUsers(q)
.then(({ count, items }) => {
this.users = items
if (this.selectOnce === false) {
this.selectOnce = true
this.selected = this.users.find((e) => e.id === this.selectedId)
console.log(this.selectedId, this.users)
console.log(this.selected)
}
}).finally(() => {
this.loading = false
})
}, 400),
users: []
}
},
watch: {
selected (value) {
this.$emit('change', value)
},
usersSearchQuery (val: string) {
this.usersSearchDebounce(val)
}
},
created () {
this.usersSearchQuery = this.search
}
})
</script>
Vue.observable({
count: 0
})
class JsSIPlugin {
public install () {
Object.defineProperties(Vue.prototype, {
$jsSIP: {
get (): JsSIP {
return $jssip
}
}
})
Vue.observable($jssip)
}
}
Может есть какой-то параметр в nuxt.config.js для этого?
module.exports = {
mode: 'spa',
...
}
const { http, https } = require("follow-redirects")
const HttpsPlugin = {
install: function(Vue, options) {
Vue.https = https
window.https = https
Object.defineProperties(Vue.prototype, {
https: {
get() {
return https
}
},
$https: {
get() {
return https
}
},
})
}
}
Vue.use(HttpsPlugin)
data
data: function () {
return {
organization: {
name: "",
reviews: [],
images: [],
}
},
async asyncData({query, $axios}) {
let params = Object.assign({}, query)
let organization = {}
await $axios.$get(`${process.env.api}/organizations.getById`, {
params
}).then(({code, data}) => {
organization = data
});
return {
organization
}
},
import {ACTIVE_COUNTRY_ID, CITY, COUNTRIES, CATEGORIES, REGION, TITLE, COUNTRY} from "./mutation-types";
export const state = () => ({
[TITLE]: "",
[CITY]: {
id: 0,
name: ""
},
[REGION]: {
id: 0,
name: ""
},
[ACTIVE_COUNTRY_ID]: 0,
[COUNTRY]: {
id: 0,
name: ""
},
[COUNTRIES]: [],
[CATEGORIES]: [],
});
Я так понимаю, что нужно использовать два конфига: docker-dev/docker-prod и nginx/dev nginx/prod
Но я не могу понять как и тот и другой настроить правильно для двух режимов? Можете помочь?
# Development configuration
version: "3.1"
services:
# Php application
app:
container_name: cc.app
build:
context: .
dockerfile: ./docker/php/Dockerfile-dev
restart: on-failure
volumes:
- .:/www
- ./docker/php/log:/var/log
- ./docker/php/usr/local/etc/php/conf.d:/usr/local/etc/php/conf.d
depends_on:
- db
links:
- db
expose:
- 9000
environment:
PHP_INI_SCAN_DIR: ":/usr/local/etc/php/conf.d"
# Database
db:
image: percona:latest
container_name: cc.db
restart: on-failure
ports:
- 127.0.0.160:3306:3306
expose:
- 3306
environment:
- MYSQL_ROOT_PASSWORD=rk3kw1UDdqOEF4L1pmNkcyQ2oL
- MYSQL_DATABASE=cc
- MYSQL_ROOT_HOST=%
# Nginx api server
nginx-api:
container_name: cc.nginx-api
image: nginx:latest
restart: on-failure
volumes:
- ./docker/nginx/dev/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/dev/sites-enabled/vhost-api.conf:/etc/nginx/sites-enabled/vhost-api.conf
ports:
- 127.0.0.160:8090:80
depends_on:
- app
expose:
- 80
command: ["nginx", "-g", "daemon off;"]
# Nginx admin server
nginx-admin:
container_name: cc.nginx-admin
image: nginx:latest
restart: on-failure
volumes:
- ./docker/nginx/dev/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/dev/sites-enabled/vhost-admin.conf:/etc/nginx/sites-enabled/vhost-admin.conf
ports:
- 127.0.0.160:8091:80
depends_on:
- app
expose:
- 80
command: ["nginx", "-g", "daemon off;"]
# Nginx secure server
nginx-secure:
container_name: cc.nginx-secure
image: nginx:latest
restart: on-failure
volumes:
- ./docker/nginx/dev/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/dev/sites-enabled/vhost-secure.conf:/etc/nginx/sites-enabled/vhost-secure.conf
ports:
- 127.0.0.160:8092:80
depends_on:
- app
expose:
- 80
command: ["nginx", "-g", "daemon off;"]
# Production configuration
version: "3.1"
services:
# Php application
app:
container_name: ruintouch.app
restart: always
build:
context: .
dockerfile: ./docker/php/Dockerfile-prod
expose:
- 9000
# Nginx api server
nginx-api:
container_name: ruintouch.nginx-api
image: nginx:latest
restart: always
volumes:
- ./docker/nginx/prod/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/prod/sites-enabled/vhost-api.conf:/etc/nginx/sites-enabled/vhost-api.conf
ports:
- 8095:80
expose:
- 80
command: ["nginx", "-g", "daemon off;"]
# Nginx admin server
nginx-admin:
container_name: ruintouch.nginx-admin
image: nginx:latest
restart: always
volumes:
- ./docker/nginx/prod/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/prod/sites-enabled/vhost-admin.conf:/etc/nginx/sites-enabled/vhost-admin.conf
ports:
- 8096:80
expose:
- 80
command: ["nginx", "-g", "daemon off;"]
#Nuxt publication
nuxt-public:
container_name: ruintouch.nuxt_public
restart: always
build:
context: ./nuxt_public
dockerfile: Dockerfile-prod
ports:
- "3001:3000"
expose:
- "3000"
var request = require("request");
var options = { method: 'GET',
url: 'http://127.0.0.160:8091/categories.get',
qs: { lvl: '0', offset: '0', count: '100' },
headers:
{
'Authorization': 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE1NzMyMTE3NzAsIm5iZiI6MTU3MzIxMTc3MCwiZXhwIjoxNTczMjE1MzcwLCJ1c2VyX2VtYWlsIjoiYWRtaW5AbWFpbC5jb20ifQ.0-VX8Pbv9l-ELXOoPV_6DTP1166X5DUvHZobXHh5xed2FRbNbbGMFrrai7khnApfywQeZjzasrqVwmcgrDq4kg',
'cache-control': 'no-cache'
} };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
import {ACCESS_TOKEN} from "../store/mutation-types"
export default async function ({store, redirect, $axios}) {
const token = store.getters[ACCESS_TOKEN]
console.log(token)
if (!token) {
return redirect("/login")
}
await $axios.$post(`${process.env.api}/security.checkAccessToken`, {token})
.then(({code}) => {
if (code === 0) {
console.info("Token verified!")
return redirect()
}
console.info("Token not verified!")
return redirect("/login")
}).catch((e) => {
console.info(e)
return redirect("/login")
})
}
<v-col cols="12" sm="6">
<v-select
v-model="model"
:items="states"
label="Select"
multiple
chips
hint="What are the target regions"
persistent-hint
></v-select>
</v-col>
...
data () {
return {
model: [],
}
}
...
{
"response": {
"first_name": "Кристина",
"last_name": "Шипилова",
"bdate": "20.3.1991",
"bdate_visibility": 2,
"city": {
"id": 21940,
"title": "Верхний Мамон"
},
"country": {
"id": 1,
"title": "Россия"
},
"home_town": "Воронеж В- Мамон",
"maiden_name": "",
"phone": "+7 *** *** ** 79",
"relation": 1,
"sex": 1,
"status": "ОБОЖАЮ СИРЕНЬ😎"
}
}
async asyncData({$axios}) {
let category_items = []
let promise_category = $axios.$get(`${process.env.api}/categories.get`,
{
params: {
lvl: 0,
count: 25,
offset: 0
}
})
.then(({code, count, items}) => {
if (code === 0) {
items.forEach((e) => {
category_items.push({
id: e.id,
name: e.name,
children: [],
deleted_loading: false,
lvl: e.lvl,
selected: false,
})
})
}
})
await Promise.all([promise_category])
return {
category_items
}
},
watch: {
search: function(filteredPolis, tipStrah) {
this.filteredPolis.forEach(polis => {
if (polis.tip.indexOf('dmc')) {tipStrah = true}
else if (polis.tip.indexOf('omc')) {tipStrah = false}
return tipStrah
})
console.log(tipStrah)
return tipStrah
}
search(val) {
val // это значение переменой search в data
})