我的应用使用Firebase API进行用户身份验证,将登录状态保存为Vuex状态中的布尔值.
当用户登录时,我设置登录状态并相应地有条件地显示登录/登出按钮.
但是当刷新页面时,vue应用程序的状态将丢失并重置为默认值
这会导致问题,即使用户登录并刷新页面时,登录状态也会设置为false,并且即使用户保持登录状态,也会显示登录按钮而不是注销按钮....
我该怎么做才能防止这种行为
我可以使用cookies 或任何其他更好的解决方案可用...
我使用webpack-simple模板,配置如下:
的package.json
{
"name": "vue-wp-simple",
"description": "A Vue.js project",
"version": "1.0.0",
"author": "v",
"private": true,
"scripts": {
"dev": "webpack-dev-server --inline --hot",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
},
"dependencies": {
"vue": "^2.3.3",
"vue-router": "^2.7.0",
},
"devDependencies": {
"babel-core": "^6.0.0",
"babel-loader": "^6.0.0",
"babel-preset-env": "^1.5.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"cross-env": "^3.0.0",
"css-loader": "^0.25.0",
"file-loader": "^0.9.0",
"style-loader": "^0.18.2",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.1",
"vue-loader": "^12.1.0",
"vue-template-compiler": "^2.3.3",
"webpack": "^2.6.1",
"webpack-dev-server": "^2.4.5"
}
}
Run Code Online (Sandbox Code Playgroud)
.babelrc
{
"presets": [
["env", { "modules": false }],
]
} …Run Code Online (Sandbox Code Playgroud) 如果keep-alive被指定为router-view,如下所示
<keep-alive>
<router-view></router-view>
</keep-alive>
Run Code Online (Sandbox Code Playgroud)
然后,当重新访问该路由时,所有路由都被有效地缓存和重新加载.
我希望能够在各个路线上指定保持活动选项.
对于许多路由并且只需要保留1或2个路由而不重新渲染缓存所有路由都是无用的
有没有这样做的方法或任何可用的解决方法
在我的firebase网络应用程序中,当新用户使用他们的电子邮件注册时,我在根提示下的电子邮件地址下创建一个节点
但问题是使用push()方法将每个新用户添加到数据库中,每个用户都使用如下所示的唯一键创建
- 用户
---- ASFTU578FE
--------- user:user1@email.com
---- FDWWE36S46
--------- user:user2@email.com
---- WERSRTT23W
--------- user:user3@email.com
现在我如何访问用户的路径,因为我不知道将为每个新用户创建的unque密钥
有没有办法在没有唯一密钥的情况下推送新用户,但我知道的密钥是user.displayName或user.email
我在我的Windows系统上使用全局安装了vue cli 3 npm i -g @vue/cli.
然后我使用生成了一个项目 vue create vue-project
我通过提示选择了所需的插件.
这创造了一个vue-projject foler.然后我将目录更改为该文件夹并运行npm run serve命令.
但我得到以下错误
PS E:\rk\workspace\vue-project> npm run serve
> vue-project@0.1.0 serve E:\rk\workspace\vue-project
> vue-cli-service serve
INFO Starting development server...
94% asset optimization
ERROR Failed to compile with 1 errors 14:58:40
error in ./src/main.js
Module build failed: Error: [BABEL] E:\rk\workspace\vue-project\src\main.js: The new decorators proposal is not supported yet. You must pass the `"decoratorsLegacy": true` option to @babel/preset-stage-2 (While processing: "E:\\rk\\workspace\\vue-project\\node_modules\\@vue\\babel-preset-app\\index.js$1")
at E:\rk\workspace\vue-project\node_modules\@babel\preset-stage-2\lib\index.js:107:11
at E:\rk\workspace\vue-project\node_modules\@babel\helper-plugin-utils\lib\index.js:18:12 …Run Code Online (Sandbox Code Playgroud) 我在颤振中有一个冻结的课程,如下所示:
@freezed
abstract class Data with _$Data {
const factory Data({
String id,
String name,
String parentId,//null if it is the root element
@Default([]) List<Data> children,
}) = _Data;
}
Run Code Online (Sandbox Code Playgroud)
该类包含一个名为的属性children,它是同一类的列表,即Data.
当前允许的最大嵌套深度为 20 级。我面临的问题是如何children通过添加或删除项目来更新特定的深度嵌套列表。此外,此更新应保持不变并返回一个新的更新Data类。
我尝试copyWith()在冻结的类上使用方法,但在我的场景中嵌套很深时无法弄清楚。
我已将以下代码添加到我的活动中并获得了所需的动画,但按下后退按钮动画不一样即活动正常关闭.如何在按下后退按钮时添加动画
public void notesAndCodeClick(View v){
Intent notesIntent = new Intent(MainActivity.this, NotesActivity.class);
ActivityOptions notesoptions = ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight());
startActivity(notesIntent, notesoptions.toBundle());
}
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我使用firebase API进行用户身份验证
我将登录状态保存为我的vuex状态中的布尔值
当用户登录时,我将登录状态设置为true并使用此选项隐藏顶部菜单上的登录按钮,并在用户注销时显示退出按钮,反之亦然.
所以我使用vuex-persisted状态来保存页面刷新的状态
处于vuex-persisted状态的dafault存储是本地存储
我没有将存储状态保存在locaal存储上,而是希望将其保存在cookie中......所以我按照vuex-persisted状态文档中描述的相同的apprach进行操作
我面临的问题是:
当我使用默认存储,即本地存储它工作,但当我使用cookie时,状态不会保存在cookie中,持久状态不起作用
当我在2个不同的选项卡上打开应用程序并且用户在一个选项卡中注销时,状态在两个选项卡中同步,但注销按钮仍显示在另一个选项卡中
我的商店
import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import * as Cookies from 'js-cookie'
import authStore from './modules/auth'
import statusStore from './modules/allStatus'
Vue.use(Vuex);
export const store = new Vuex.Store({
modules: {
authStore,
statusStore
},
plugins: [
createPersistedState({
getState: (key) => Cookies.getJSON(key),
setState: (key, state) => Cookies.set(key, state, { expires: 3, secure: true })
})
]
});
Run Code Online (Sandbox Code Playgroud) 我使用相机包来实现简单的功能。我主要遵循包提供的示例。当我打开相机小组件页面时,程序包会自动提示提供相机和麦克风的权限。单击允许这两种权限后,调试器将暂停,但出现异常:
Exception has occurred.
FlutterError (A CameraController was used after being disposed.
Once you have called dispose() on a CameraController, it can no longer be used.).
Run Code Online (Sandbox Code Playgroud)
这是所需的代码:
class CameraPage extends StatefulWidget {
@override
_CameraPageState createState() => _CameraPageState();
}
class _CameraPageState extends State<CameraPage>
with WidgetsBindingObserver {
CameraController _controller;
List<CameraDescription> _availableCameras;
...
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
_initialize();
}
Future<void> _initialize() async {
await _getCameras();
_controller = CameraController(_availableCameras[0], ResolutionPreset.high);
await _controller.initialize();
if (!mounted) {
return;
}
setState(() …Run Code Online (Sandbox Code Playgroud) 我的应用程序是使用 aMaterialApp作为根小部件构建的。对于这个材质应用,我添加了一个主题如下:
MaterialApp(
theme: myTheme,
home: MyHomePage(),
...
)
final ThemeData myTheme = _buildTheme();
ThemeData _buildTheme() {
final ThemeData base = ThemeData.light();
return base.copyWith(
...
textTheme: _buildMyTextTheme(base.textTheme),
primaryTextTheme: _buildMyTextTheme(base.primaryTextTheme),
accentTextTheme: _buildMyTextTheme(base.accentTextTheme),
pageTransitionsTheme: PageTransitionsTheme(builders: {
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
}));
}
TextTheme _buildMyTextTheme(TextTheme base) {
return base
.copyWith(
headline:
base.headline.copyWith(fontSize: 20.0, fontWeight: FontWeight.w500),
title: base.title.copyWith(fontSize: 18.0, fontWeight: FontWeight.w400),
subhead:
base.subhead.copyWith(fontSize: 16.0, fontWeight: FontWeight.w400),
body1: base.body1.copyWith(fontSize: 14.0, fontWeight: FontWeight.w400),
body2: base.body2.copyWith(fontSize: 14.0, fontWeight: FontWeight.w500),
caption: base.caption.copyWith(
fontWeight: FontWeight.w400,
fontSize: 12.0,
),
) …Run Code Online (Sandbox Code Playgroud) 我是新手使用vue-cli webpack模板 我想使用firebase作为vueapp的数据库我已经这样做将Firebase导入我的应用程序
main.js
//imported rest all required packages just dint mention here
import * as firebase from 'firebase'
let config = {
apiKey: " - XXXXXXXXCXCC",
authDomain: "XXXXXXXXX",
databaseURL: "XXXXXCCCX",
storageBucket: "XXXXXXXXXXX",
messagingSenderId: "XXXXXXXXXX"
};
firebase.initializeApp(config);
new Vue({
el: '#app',
router,
store,
render: h => h(App)
})
Run Code Online (Sandbox Code Playgroud)
现在在我的signup.vue文件中,我必须再次导入以下内容
import * as firebase from 'firebase'
Run Code Online (Sandbox Code Playgroud)
为了在我的方法中使用以下内容
firebase.auth().createUserWithEmailAndPassword(uEmail, uPassword).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});
Run Code Online (Sandbox Code Playgroud)
我的问题是我必须导入
import * as firebase from …Run Code Online (Sandbox Code Playgroud) 我在Stackheight的小部件中有一个容器100.0。它使用Positioned小部件定位在中心,如下所示
Container(
width:100.0,
height:100.0,
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Positioned(
top: 40.0,
child: Container(
width: 20.0,
height: 20.0,
color: Colors.red,
),
)
],
)
)
Run Code Online (Sandbox Code Playgroud)
我想以这样的方式为红色容器设置动画,当点击它时它会到达父容器的底部,当再次点击时会弹回到顶部然后回到中心。
我尝试使用,Curves.elasticOut但这对我来说还不够弹跳。我如何实现这种效果