我在Angular2的Component中实现了以下功能:
export class MypageEditComponent {
ngOnInit() {
this.timer = Observable.timer(100, 100);
this.timer.subscribe(t => {
this.setFormData();
}
private setFormData() {
this.editUserAcountType = this.authStore.registerInfo.account_type;
this.editAddress = this.authStore.registerInfo.email;
this.editUserName = this.authStore.registerInfo.username;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望在Observable.timer
正确存储值后停止重复setFormData()
.
但不知道怎么样,请告诉我.
我想在 Nuxt.js 中实现以下内容:
1.使用不同网址的同一个页面。
具体来说,我想/pages/users/_userId.vue
与/users/{userId}
,/users/{userId}/follow
和一起使用/users/{userId}/follower
。
我检查了这个,有以下问题。
- https://github.com/nuxt/nuxt.js/issues/2693
但这与我想要实现的有点不同。
我想将 pass 参数用于查询参数。
2.通过路径参数识别要显示的组件
看这里的代码会更快。
?/pages/users/_userId.vue`
<template>
<div class="user">
<div class="user__contents">
<div class="user__contents__main">
<UserInfo/>
<PostSection/> -> use if URL /users /{userId}
<FollowSection/> -> use if URL /users/{userId}/follow
<FollowerSection/> -> use if URL /users/{userId}/follower
</div>
</div>
</div>
</template>
<script>
import UserInfo from '~/components/organisms/users/UserInfo'
import PostsSection from '~/components/organisms/users/PostsSection'
import FollowSection from '~/components/organisms/users/FollowSection'
import FollowerSection from '~/components/organisms/users/FollowerSection'
Run Code Online (Sandbox Code Playgroud)
...
我应该怎么做才能实现这些?
我正在尝试将django应用程序合并到其中静态html占多数的网站。目录结构如下。
root/
?? var/
??? ? www/
?????? html/
????? ? static
????? ? ?style.css
????? ? ?base.js
????? ?
????? ? web/
??????? ?head.html
??????? ?footer.html
??????? ?base.html
??
?? opt/
???? django/
?????? project/
??????
?????? apps/
???????? views.py
????? ?? template/
????? ? ? index.html
Run Code Online (Sandbox Code Playgroud)
我想在中/opt/django/template/index.html
阅读html /var/www/html/web/
。我不知道如何包括在内。
{% include "/var/www/html/web/head.html" %}
没用 我不想更改目录结构。
我正在尝试使用Angular2和Django Rest Framework创建一个简单的博客应用程序.我在Django中实现分页,但我不知道如何在Angular中渲染它.
API具有以下结构.条目每5个条目分页.
ng2app/src目录/应用/模型/ entries.model.ts
export interface IEntries {
count: any,
next: any,
previous: any,
results: IResults[]
}
export interface IResults {
title: string,
body: string,
created_at: any,
updated_at: any
}
Run Code Online (Sandbox Code Playgroud)
ng2app/src目录/应用/服务/ entries.service.ts
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import 'rxjs/add/operator/toPromise';
import { IEntries } from '../models/entries.model';
@Injectable()
export class EntriesService {
constructor(
private http: Http
){
}
getEntries(page: number){
return this.http
.get(`http://127.0.0.1:8000/api/entries/?limit=5&offset=` +((page * 5)-5))
.toPromise()
.then(response => response.json())
.catch(this.handleError);
}
private …
Run Code Online (Sandbox Code Playgroud) 我正在按如下方式配置 Nuxt.js 的 VUEX。
store
??? README.md
??? posts
? ??? actions.js
? ??? getters.js
? ??? index.js
? ??? mutations.js
? ??? utils
? ??? getPostById.js
??? index.js
Run Code Online (Sandbox Code Playgroud)
我@nuxtjs/axios
在 nuxt.config.js 中添加了模块并使其可以this.$axios.$get
在操作中使用。
但是,您不能在 store/posts/utils/getPostById.js 中使用 A。会发生
错误Cannot read property '$axios' of undefined
。
每个代码描述如下。
? 商店/index.js
import Vuex from 'vuex'
import postsModule from './posts'
new Vuex.Store({
modules: {
posts: postsModule
}
})
Run Code Online (Sandbox Code Playgroud)
?store/posts/index.js
import actions from './actions'
import getters from './getters'
import mutations from './mutations' …
Run Code Online (Sandbox Code Playgroud) 假设有一个如下所示的列表.
items = [
{ id: 1,
name: "one"
},
{ id: 3,
name: "thee"
},
{ id: 5,
name: "five"
},
{ id: 6,
name: "six"
},
];
lists = [
{ id: 5,
name: "five"
},
{
id: 9,
name: "nine"
},
];
Run Code Online (Sandbox Code Playgroud)
我希望只有在使用ngFor处理项目时才显示项目,并且项目ID包含在带有ngIf的列表中.但是我不知道怎么做
<div *ngFor="let item of items">
<p *ngIf = "How can I write it here?">
{{ item.name }}
<p>
<div>
Run Code Online (Sandbox Code Playgroud) 我无法连接到在本地环境 (Mac OS X) 中使用 Docker 创建的 Mysql。
我创建了以下配置文件。
version: '2'
services:
db:
image: mysql:5.7
environment:
MYSQL_DATABASE: mysqldatabase
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
MYSQL_ROOT_PASSWORD: password
ports:
- "33333:3306"
container_name: mysql-db
volumes:
- db-data:/var/lib/mysql
volumes:
db-data:
driver: local
Run Code Online (Sandbox Code Playgroud)
然后,我使用以下命令启动了 mysql 的 docker 容器。
$ docker-compose up -d
$ docker start mysql-db
Run Code Online (Sandbox Code Playgroud)
到此为止没有问题,但是尝试连接mysql时出现错误。
$ mysql -p 33333 -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Run Code Online (Sandbox Code Playgroud)
请告诉我如何处理。
javascript ×4
angular ×3
django ×2
nuxt.js ×2
python ×2
typescript ×2
vue.js ×2
axios ×1
docker ×1
mysql ×1
pagination ×1
rxjs ×1
rxjs5 ×1
vuex ×1