我正在尝试使用 Vue 解决问题,但我遇到了一些麻烦:
1:我无法从 router/index.js 文件访问我的 getter。(我可以访问它,但它像一个带有返回函数的函数一样返回,我无法调用并获取值)
2:我无法正确设置警卫。使用 Angular 就容易多了
我在这里做错了什么?有什么建议?
路由器代码
/* eslint-disable no-undef */
import Vue from "vue";
import VueRouter from "vue-router";
// import auth from '../store/modules/auth';
import { createNamespacedHelpers } from "vuex";
const { mapGetters } = createNamespacedHelpers("auth");
// import store from '../store';
Vue.use(VueRouter);
const routes = [
{
path: "/",
name: "Home",
component: () => import("../components/Home.vue"),
meta: { requiresAuth: true }
},
{
path: "/users",
name: "Users",
component: () => import("../components/Users/Users.vue"),
meta: { requiresAuth: true } …Run Code Online (Sandbox Code Playgroud) 我刚刚学习 Flutter 并陷入了这个错误:
No Scaffold widget found.
Home widgets require a Scaffold widget ancestor.
The specific widget that could not find a Scaffold ancestor was: Home
The ancestors of this widget were
Run Code Online (Sandbox Code Playgroud)
但正如您从我的代码中看到的那样,我确实有一个脚手架,并且我尝试尽可能地添加它,但我没有为之工作。
我在那里所做的或没有注意到的原因可能是什么?
import 'package:firebase_redux_app/services/firebase.auth.dart';
import 'package:flutter/material.dart';
// import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_redux_app/services/firestore.dart';
import 'package:provider/provider.dart';
import 'package:firebase_redux_app/screens/home/brewList.dart';
import 'package:firebase_redux_app/models/brew.dart';
class Home extends StatelessWidget {
final AuthService _auth = AuthService();
@override
Widget build(BuildContext context) {
void _showSettingsPanel() {
showBottomSheet(
context: context,
builder: (context) {
return Container(
padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 60.0), …Run Code Online (Sandbox Code Playgroud) 假设我有一个函数,可以从数据库中获取一些数据。
findById(id) {
return Model.findById(id)
}
Run Code Online (Sandbox Code Playgroud)
我需要重新组织这样的回报user data:
{
name: "Tom",
age: 57
}
Run Code Online (Sandbox Code Playgroud)
变成这样:
{
message: "User is found successfully",
success: true,
user: user
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我可以用一个Promise "then"部分来管理它,如下所示:
return Model.findById(id)
.then(user => {
if (!user) {
logger.warn(`Coundn't find user with id: ${id}`);
return { message: `Coundn't find user with id: ${id}`, success: false, user: null };
}
return { message: `User with id: ${id}`, success: true, user: user };
})
.catch(err => {
if (err) { …Run Code Online (Sandbox Code Playgroud)