虽然有类似的问题,但我无法创建具有多个功能的文件.不确定该方法是否已经过时,因为RN正在快速发展.如何在本机中创建全局辅助函数?
我是React Native的新手.
我想要做的是创建一个充满许多可重用函数的js文件,然后将其导入组件并从那里调用它.
到目前为止我一直在做的事情可能看起来很愚蠢,但我知道你会在这里提出要求.
我尝试创建一个类名Chandu并像这样导出它
'use strict';
import React, { Component } from 'react';
import {
AppRegistry,
Text,
TextInput,
View
} from 'react-native';
export default class Chandu extends Component {
constructor(props){
super(props);
this.papoy = {
a : 'aaa'
},
this.helloBandu = function(){
console.log('Hello Bandu');
},
}
helloChandu(){
console.log('Hello Chandu');
}
}
Run Code Online (Sandbox Code Playgroud)
然后我将其导入任何所需的组件.
import Chandu from './chandu';
Run Code Online (Sandbox Code Playgroud)
然后像这样称呼它
console.log(Chandu);
console.log(Chandu.helloChandu);
console.log(Chandu.helloBandu);
console.log(Chandu.papoy);
Run Code Online (Sandbox Code Playgroud)
唯一有效的是第一个console.log,这意味着我正在导入正确的路径,但不会导入任何其他路径.
请问这样做的正确方法是什么?
我有一个Vue 2项目,有许多(50+)单文件组件.我使用Vue-Router进行路由,使用Vuex进行状态.
有一个名为helpers.js的文件,它包含许多通用函数,例如大写字符串的第一个字母.这个文件看起来像这样:
export default {
capitalizeFirstLetter(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
}
Run Code Online (Sandbox Code Playgroud)
我的main.js文件初始化了应用程序:
import Vue from 'vue'
import VueResource from "vue-resource"
import store from "./store"
import Router from "./router"
import App from "./components/App.vue"
Vue.use(VueResource)
const app = new Vue({
router: Router,
store,
template: '<app></app>',
components: { App }
}).$mount('#app')
Run Code Online (Sandbox Code Playgroud)
我的App.vue文件包含模板:
<template>
<navbar></navbar>
<div class="container">
<router-view></router-view>
</div>
</template>
<script>
export default {
data() {
return {
//stuff
}
}
}
</script> …Run Code Online (Sandbox Code Playgroud) 这里有一些我缺少的基本理解/理论.我不明白这些函数调用之间的区别:
$distributors = $store->distributors();
$distributors = $store->distributors;
$distributors = $store->distributors()->get();
$distributors = $store->distributors->get();
Run Code Online (Sandbox Code Playgroud)
我在这里要完成的是获得一个商店经销商列表(多对多的关系),他们将每个经销商的啤酒列表列入一个巨大的列表.
foreach ($distributors as $distributor)
{
$available_beers = array_merge($distributor->beers(), $available_beers);
}
Run Code Online (Sandbox Code Playgroud)
我不知道这是否是最好的方法,我无法让它工作.与第一个方法列表类似,我不知道我是否需要->$beers或->$beers()
更新
感谢所有回答的人!这对我来说将是一个很好的参考.我最大的教训是获取集合与获取查询构建器/关系对象之间的区别.为了将来参考那些发现这个问题的人,这是我在我的控制器中设置的内容:
$store = $this->store->find($id)->first();
$distributors = $store->distributors;
$beers = [];
foreach ($distributors as $distributor){
$beers = array_merge($distributor->beers->lists('name', 'id'), $beers);
}
Run Code Online (Sandbox Code Playgroud) I am a beginner with VueJs and this is my first App:
import { BootstrapVue } from 'bootstrap-vue'
import { createApp } from 'vue'
import App from './App.vue'
const myApp = createApp(App)
myApp.use(BootstrapVue)
myApp.mount('#app')
Run Code Online (Sandbox Code Playgroud)
And when I save, nothing appears in my browser and it show this message in the Command:
warning in ./src/main.js
"export 'default' (imported as 'Vue') was not found in 'vue'
Run Code Online (Sandbox Code Playgroud) 首先,我知道文档说明:
注意:您不应该模拟请求外观.相反,在运行测试时,将您想要的输入传递给HTTP帮助程序方法,例如调用和发布.
但是那些类型的测试更像是集成或功能,因为即使你正在测试一个控制器(SUT你),你也不会将它与它的依赖关系脱钩(Request和其他人一样,稍后会更多).
所以我在做什么,为了做正确的TDD循环,被嘲讽Repository,Response和Request(我有问题).
我的测试看起来像这样:
public function test__it_shows_a_list_of_categories() {
$categories = [];
$this->repositoryMock->shouldReceive('getAll')
->withNoArgs()
->once()
->andReturn($categories);
Response::shouldReceive('view')
->once()
->with('categories.admin.index')
->andReturnSelf();
Response::shouldReceive('with')
->once()
->with('categories', $categories)
->andReturnSelf();
$this->sut->index();
// Assertions as mock expectations
}
Run Code Online (Sandbox Code Playgroud)
这非常好用,它们遵循Arrange,Act,Assert风格.
问题在于Request,如下所示:
public function test__it_stores_a_category() {
Redirect::shouldReceive('route')
->once()
->with('categories.admin.index')
->andReturnSelf();
Request::shouldReceive('only')
->once()
->with('name')
->andReturn(['name' => 'foo']);
$this->repositoryMock->shouldReceive('create')
->once()
->with(['name' => 'foo']);
// Laravel facades wont …Run Code Online (Sandbox Code Playgroud) 我注意到在 Chrome 和 Firefox 中,我的代客受保护网站均显示为不安全。它在 Safari 中运行良好。最近有人经历过这种情况吗?
当我这样做时valet secured,我可以看到我的网站(应该)如附件一样受到保护。
怀疑这可能与我最近的更新有关。
目前使用 Composer 2 / Laravel 9 / PHP 8.0 / Value 3
尝试过重新安装 valet、重新启动 valet、链接/取消链接以及安全/不安全,但没有成功。
当我们在控制器中使用Laravel 表单请求并且验证失败时,表单请求将重定向回errors变量。
redirection当数据无效时,如何禁用并返回自定义错误响应?
我将使用表单请求来GET|POST|PUT请求类型。
我试过这Validator门课来解决我的问题,但我必须使用表单请求。
$validator = \Validator::make($request->all(), [
'type' => "required|in:" . implode(',', $postTypes)
]);
if ($validator->fails()) {
return response()->json(['errors' => $validator->errors()]);
}
Run Code Online (Sandbox Code Playgroud) 从教程复制代码后出现此错误。它已被弃用,我尝试解决它:
.../app/Http/Helpers/helpers.php 中不再支持带大括号的数组和字符串偏移访问语法
我的代码副本:
if (!function_exists("pkcs5_unpad_e")) {
function pkcs5_unpad_e($text) {
$pad = ord($text{strlen($text) - 1});
if ($pad > strlen($text))
return false;
return substr($text, 0, -1 * $pad);
}
}
Run Code Online (Sandbox Code Playgroud)
我的编辑:替换{....}为[.....]==> HTTP ERROR 500
if (!function_exists("pkcs5_unpad_e")) {
function pkcs5_unpad_e($text) {
$pad = ord($text[strlen($text) - 1]);
if ($pad > strlen($text))
return false;
return substr($text, 0, -1 * $pad);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用 Ubuntu 20.04 DigitalOcean Cyberpanel 服务器和 PHP 8。
当我尝试更新 vuejs 中的数据字段时,出现此错误。
data() {
return {
form : useForm({
imageFile : null,
img_id : null,
}),
product_images : this.images,
}
},
Run Code Online (Sandbox Code Playgroud)
在这里,我在用户发送发布请求成功后更新product_images。
像这样。
this.form.post(url, {
onStart : () => {
Inertia.on('progress', (event) => {
if (event.detail.progress.percentage) {
NProgress.set((event.detail.progress.percentage / 100) * 0.98);
}
});
},
onFinish : () => {
this.product_images = this.images;
},
})
Run Code Online (Sandbox Code Playgroud)
在模板中显示产品图像就像
<div v-for="image in product_images" class="col-xl-4 col-lg-6 col-12 mb-3" :key="image.id">
<input-image @changeImage="onChangeImage" :id="image.id" :image="image.image" />
</div>
Run Code Online (Sandbox Code Playgroud)
当 post 请求后 Product_images 发生变化时,product_images 不会在 DOM 中更新,但会出现此错误,为什么? …
我已经在我的 laravel 项目上maatwebsite/excel使用命令行命令进行了安装composer require maatwebsite/excel。我已经按照指南设置了正确的别名和提供程序,但是当我运行时php artisan make:export ExportTimesheet --model=Timesheet,它会抛出错误:
BadMethodCallException 方法 Illuminate\Foundation\Application::share 不存在
这是生成错误的方法:
protected function bindClasses()
{
// Bind the format identifier
$this->app['excel.identifier'] = $this->app->share(function($app) {
return new FormatIdentifier($app['files']);
});
}
Run Code Online (Sandbox Code Playgroud)
我的提供商和别名是:
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Auth\AuthServiceProvider::class,
Illuminate\Broadcasting\BroadcastServiceProvider::class,
Illuminate\Bus\BusServiceProvider::class,
Illuminate\Cache\CacheServiceProvider::class,
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
Illuminate\Cookie\CookieServiceProvider::class,
Illuminate\Database\DatabaseServiceProvider::class,
Illuminate\Encryption\EncryptionServiceProvider::class,
Illuminate\Filesystem\FilesystemServiceProvider::class,
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
Illuminate\Hashing\HashServiceProvider::class,
Illuminate\Mail\MailServiceProvider::class,
Illuminate\Notifications\NotificationServiceProvider::class,
Illuminate\Pagination\PaginationServiceProvider::class,
Illuminate\Pipeline\PipelineServiceProvider::class,
Illuminate\Queue\QueueServiceProvider::class,
Illuminate\Redis\RedisServiceProvider::class,
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
Illuminate\Session\SessionServiceProvider::class,
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
Maatwebsite\Excel\ExcelServiceProvider::class,
/*
* Package Service Providers...
*/
/*
* …Run Code Online (Sandbox Code Playgroud) laravel ×7
php ×3
vue.js ×3
arrays ×1
javascript ×1
laravel-5 ×1
laravel-5.1 ×1
methods ×1
react-native ×1
reactjs ×1
tdd ×1
unit-testing ×1
v-for ×1
validation ×1
vue-router ×1
vuejs3 ×1