我是Vue和Vuex的新手,我试图弄清楚如何对存储中的数据进行突变。
当前在我的州中,默认用户名是“ default”,我想将其更改为“ otto”,以后将无法从数据库中获取此信息。但是出于理解的目的,我只是想让它起作用。
此时,组件已正确加载,并且显示“默认”。没有错误。
store.js:
// store.js
export default {
state: {
username: 'default'
},
getters: {
},
mutations: {
changeUsername (state) {
state.username = 'otto'
}
},
actions: {
changeUsername (context) {
context.commit('changeUsername')
}
}
}
Run Code Online (Sandbox Code Playgroud)
vue文件:
// Basic.vue
<template>
<div>
<p>{{ username }}</p>
</div>
</template>
<script>
import { mapState } from 'vuex';
import { mapMutations } from 'vuex';
import { mapActions } from 'vuex';
export default {
name: "basic",
computed: {
...mapState([
'username'
])
},
methods: { …Run Code Online (Sandbox Code Playgroud) 我收到以下错误。奇怪的是,我很确定数据在那里,因为在我的 vue 插件中,我可以看到它成功地从 vuex 商店中获取了信息。我最初的猜测是,不知何故,在创建模板时,还没有从商店中获取数据?
Vue warn]: Error in render: "TypeError: Cannot read property 'length' of undefined"
Run Code Online (Sandbox Code Playgroud)
数据: 'spaces' 是从 store 中获取的。
export default {
name: "myspaces",
data() {
return {
filterMaxLength: 3,
selectedSpace: 0,
selectedRoom: 0
}
},
created() {
// Default selected space (first in json)
this.selectedSpace = this.spaces[0].id;
// Default selected room (first in json)
this.selectedRoom = this.spaces[0].rooms[0].id;
},
computed: {
// Get 'spaces' from store.
...mapState([
'spaces'
])
}
Run Code Online (Sandbox Code Playgroud)
模板:
<template>
<div>
<v-flex v-if="spaces.length < filterMaxLength"> …Run Code Online (Sandbox Code Playgroud) 是否有可能降低<v-carousel>?的高度?我在文档中看到他们正在研究它,但是它已经实现了吗?如果没有,是否有解决方法?我只是想设置一个最大高度.
我的整个 Laravel 控制器无法工作。当我向该控制器 index() 发出 get 请求时,它工作得很好。但是当我向该控制器发送 post 请求来 store() 时,它不起作用。
当我尝试排除故障时,我开始注释代码或使用 dd()。然后很快注意到,当我注释掉整个控制器时,它对错误没有任何改变。(或者当我 dd($user_id) 没有任何改变时)。
我的错误:
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message
Run Code Online (Sandbox Code Playgroud)
路线文件:
<?php
Route::get('/', function () {
return view('welcome');
});
Route::get('/test','TestController@index');
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home')->middleware('auth');
Route::get('/inspirations','InspirationsController@index')->middleware('auth');
Route::get('/spaces','SpacesController@index');
Route::get('/user/{id}','UserController@index'); // other profiles
Route::get('/user','UserController@myprofile'); // my profile
Route::get('/mymessages','MessagesController@index'); // messages
Route::get('/testauth/', function()
{
var_dump(Auth::user()->id);
// your code here
});
Route::post('/pins/{inspiration_id}/{room_id}','PinsController@store')->middleware('auth');
Route::post('/editRoom/{id}/{name}/{description}','RoomsController@update');
// how i was doing it --> Route::post('/sendmessage/{receive_id}/{message}','MessagesController@store');
Route::post('/sendmessage','MessagesController@store');
Auth::routes();
Run Code Online (Sandbox Code Playgroud)
我的控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request; …Run Code Online (Sandbox Code Playgroud) 我只想在移动设备上添加课程。我在使用vuetify之前已经做到了,但是使用vue似乎更困难:
码:
<div class="{'mobileSnackBar': breakpoint.xs}">
<p> This is my snackbar </p>
</div>
Run Code Online (Sandbox Code Playgroud)
在vuetify中,您可以$vuetify.breakpoint.xs使用bootstrap获得类似的效果?或者,请推荐其他方法。
我在 digitalocean 上有一个服务器,我想将它连接到 git。(甚至不推送任何东西,只需连接)。
当我测试我的连接时:ssh -T git@github.com.
我收到错误消息,表示git@github.com: Permission denied (publickey).我已尝试一切方法来使连接正常工作。在我的计算机上,连接有效,并且我的根服务器上的密钥链接到我的本地id_rsa. 密钥是相同的,我ssh-keygen -l -E md5 -f ~/.ssh/id_rsa.pub在我的服务器和计算机上都检查了这一点。
有任何想法吗?我被困住了,快要疯了。
我正在尝试通过添加类来单击它时使导航处于活动状态nav-selected.我已经看到过这样的其他问题,但它们是相关的,v-model因此它们没有帮助我.
我需要确保将它添加到商店中,以便即使刷新后我也能始终看到哪个页面处于活动状态.但是我收到以下错误:
Navigation.vue:
<template>
<v-container>
<v-layout align-center>
<!-- Logo -->
<v-flex sm2>
<img src="http://beam.space/img/icon.png" height="30px">
</v-flex>
<!-- Navigation -->
<v-flex sm8>
<v-layout wrap justify-center>
<v-flex sm2>
<router-link to="/myspaces">
<h2 @click="setActiveNav(0)" :class="{'nav-selected': activeNavigation === 0}" class="nav-text">My Spaces</h2>
</router-link>
</v-flex>
<v-flex sm2>
<router-link to="/inspirations">
<h2 @click="setActiveNav(1)" :class="{'nav-selected': activeNavigation === 1}" class="nav-text">Inspirations</h2>
</router-link>
</v-flex>
</v-layout>
</v-flex>
<v-flex sm2>
<p>profile</p>
</v-flex>
</v-layout>
</v-container>
</template>
<script>
import { mapState } from 'vuex';
export default {
name: "navigation",
computed: {
...mapState([
'activeNavigation' …Run Code Online (Sandbox Code Playgroud) v-flex如果元素的网格大小为xs(因此仅在移动设备上),则尝试仅向添加一个类。下面的代码显示了其背后的思考过程。但是,这不起作用,因此如何应用仅适用于特定网格大小的类?
<v-flex xs12 lg6 :class="{'roomPadding': xs != visible }">
<p> My room </p>
</v-flex>
Run Code Online (Sandbox Code Playgroud) 我目前有一个查询,我查找具有名字和姓氏的特定用户.但是,我想确保使用它的用户看不到自己的名字出现在列表中(它用于消息系统).
这是我的laravel php查询:
$users = User::where('firstname', 'LIKE', $firstname.'%')->whereNotIn('id', $user_id)->get();
Run Code Online (Sandbox Code Playgroud)
我想检查具有匹配名字的用户,但我希望它不会抓住id为的用户user_id.有人知道怎么做吗?
vue.js ×6
vuejs2 ×6
laravel ×3
laravel-5 ×2
php ×2
vuetify.js ×2
vuex ×2
bootstrap-4 ×1
git ×1
github ×1