pengqy的个人博客

小小菜坤前端

当我们项目中的某个模块为第三方拉取的,在我们git add添加文件时会报如下错误

1
fatal: in unpopulated submodule 'themes/next'

1. 先取消第三方的远程连接,然后执行以下命令即可解决

1
git rm -rf --cached .\next\(此为文件夹名称)

git项目初始化后没提交本地代码直接pull导致文件丢失问问题

1. 此时切勿慌张乱删文件

2. 在命令行中进入项目目录输入以下命令查看你的git操作日志

1
git reflog

3. 命令执行完出现类似下图结果,根据提交时的备注找到pull之前的git记录找到图片上的黄色字体的id

title text

4. 复制commitId执行以下命令重置到pull之前的样子

1
git reset --hard (复制的commitId)

Git–断开与远程仓库的连接并连接新仓库

1. 查看远程连接

1
git remote -v

2. 取消与远程仓库的连接

1
git remote remove origin

3. 初始化仓库

1
git init

4. 添加所有文件

1
git add .

5. 提交所有文件到本地仓库

1
git commit -m '备注信息'

6. 连接到远程仓库

1
git remote add origin 你的远程仓库地址

“你的远程仓库地址”为新建的空仓库

7. 将项目推送到远程仓库

1
git push -u origin master

如果出现下面错误可能是因为远程仓库原有的README.md或者.gitignore等文件没有pull到本地仓库而导致的冲突

title text

输入git pull –rebase origin master将文件拉到本地后重新输入步骤7即可解决

1、全局安装 npm-check-updates

1
npm install -g npm-check-updates

2、在当前项目的目录下执行以下命令,查看所有存在的更新

1
ncu

3、也可以通过执行以下命令查看所有可用的相关命令行 (命令变动或者无效时查看命令)

1
ncu -h

3、更新package.json文件

1
ncu -u

4、安装最新依赖

1
npm install

常用命令

1、显示可下载版本的部分列表

1
nvm list available 

2、安装指定的版本的nodejs

1
nvm install xx.xx.xx 

3、查看目前已经安装的node版本

1
nvm ls 

4、删除指定的node版本

1
nvm uninstall xx.xx.xx 

5、使用指定的node版本

1
nvm use xx.xx.xx

6、设置默认的node版本,不然每次关掉再打开都需要重新选择(1.1.10已经没有此命令,会默认选择上次use的版本)

1
nvm alias default xx.xx.xx

常用查询命令

1、安装模块

1
2
3
4
5
6
7
npm install <package>                                安装包,默认会安装最新的版本
npm install <package>@<version>    安装指定版本
npm install <package> --save 或 npm install <package> -S 安装包并将安装包信息将加入到dependencies(生产阶段的依赖)
npm install <package> --save-dev 或 npm install <package> -D    安装包并将安装包信息将加入到devDependencies(开发阶段的依赖),所以开发阶段一般使用它
npm install <package> --save-optional 或 npm install <package> -O 安装包并将安装包信息将加入到optionalDependencies(可选阶段的依赖)
npm install <package> --save-exact 或 npm install <package> -E 精确安装指定模块版本
npm install gulp -g 或 npm install gulp --global 全局安装包

2、卸载模块

1
2
3
npm uninstall <package> --save-dev 或 npm uninstall <package> -D       卸载开发版本的模块
npm uninstall <package> --save 或 npm uninstall <package> -S       卸载生产版本的模块
npm uninstall <package> --save-optional 或 npm uninstall <package> -O 卸载可选依赖版本的模块

3、更新模块

1
2
3
4
5
npm update              更新包,将包更新到最新版本
npm update <package> 更新指定包
npm update -g 更新全局包
npm update -g <package> 更新指定的全局包
npm outdated [-g] 列出所有已经过时的包,可以及时进行包的更新

4、查看更新的模块

1
2
3
4
5
6
npm outdated 查看当前项目所有依赖包那些可以更新
npm -g outdated 查看全局包那些可以更新
npm ls 查看安装的模块及依赖
npm ls -g 查看全局安装的模块及依赖
npm ls --depth 0 查看当前项目的依赖模块
npm ls -g --depth 0 查看全局依赖模块命令
阅读全文 »

mac上node版本和fsevents版本

当node升级到12.0版本以上在进行npm install时会报错

以下是错误日志:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
../../../../nan/nan_converters_43_inl.h:22:1: warning: 'ToBoolean' is deprecated: ToBoolean can never throw. Use Local version. [-Wdeprecated-declarations]
X(Boolean)
^
../../../../nan/nan_converters_43_inl.h:18:12: note: expanded from macro 'X'
val->To ## TYPE(isolate->GetCurrentContext()) \\\n ^
<scratch space>:201:1: note: expanded from here
ToBoolean
^
/Users/rene/.node-gyp/12.1.0/include/node/v8.h:2523:3: note: 'ToBoolean' has been explicitly marked deprecated here
V8_DEPRECATE_SOON(\"ToBoolean can never throw. Use Local version.\",
^
/Users/rene/.node-gyp/12.1.0/include/node/v8config.h:322:29: note: expanded from macro 'V8_DEPRECATE_SOON'
declarator __attribute__((deprecated(message)))
^
In file included from ../fsevents.cc:6:
In file included from ../../../../nan/nan.h:221:
In file included from ../../../../nan/nan_converters.h:67:
../../../../nan/nan_converters_43_inl.h:40:1: warning: 'BooleanValue' is deprecated: BooleanValue can never throw. Use Isolate version. [-Wdeprecated-declarations]
X(bool, Boolean)
^
../../../../nan/nan_converters_43_inl.h:37:15: note: expanded from macro 'X'
return val->NAME ## Value(isolate->GetCurrentContext()); \\\n ^
<scratch space>:208:1: note: expanded from here
BooleanValue
^
/Users/rene/.node-gyp/12.1.0/include/node/v8.h:2561:3: note: 'BooleanValue' has been explicitly marked deprecated here
V8_DEPRECATED(\"BooleanValue can never throw. Use Isolate version.\",
^
/Users/rene/.node-gyp/12.1.0/include/node/v8config.h:307:29: note: expanded from macro 'V8_DEPRECATED'
declarator __attribute__((deprecated(message)))
^
In file included from ../fsevents.cc:6:
In file included from ../../../../nan/nan.h:222:
In file included from ../../../../nan/nan_new.h:189:
../../../../nan/nan_implementation_12_inl.h:103:42: error: no viable conversion from 'v8::Isolate *' to 'Local<v8::Context>'
return scope.Escape(v8::Function::New( isolate
^~~~~~~
/Users/rene/.node-gyp/12.1.0/include/node/v8.h:183:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'v8::Isolate *' to 'const v8::Local<v8::Context> &' for 1st argument
class Local {
^
/Users/rene/.node-gyp/12.1.0/include/node/v8.h:183:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'v8::Isolate *' to 'v8::Local<v8::Context> &&' for 1st argument
/Users/rene/.node-gyp/12.1.0/include/node/v8.h:187:13: note: candidate template ignored: could not match 'Local<type-parameter-0-0>' against 'v8::Isolate *'
V8_INLINE Local(Local<S> that)
^
/Users/rene/.node-gyp/12.1.0/include/node/v8.h:4126:22: note: passing argument to parameter 'context' here
Local<Context> context, FunctionCallback callback,
^
In file included from ../fsevents.cc:6:
In file included from ../../../../nan/nan.h:222:
In file included from ../../../../nan/nan_new.h:189:
../../../../nan/nan_implementation_12_inl.h:337:37: error: too few arguments to function call, expected 2, have 1
return v8::StringObject::New(value).As<v8::StringObject>();
~~~~~~~~~~~~~~~~~~~~~ ^
/Users/rene/.node-gyp/12.1.0/include/node/v8.h:5380:3: note: 'New' declared here
static Local<Value> New(Isolate* isolate, Local<String> value);
^
In file included from ../fsevents.cc:6:
In file included from ../../../../nan/nan.h:222:
In file included from ../../../../nan/nan_new.h:189:
../../../../nan/nan_implementation_12_inl.h:337:58: error: expected '(' for function-style cast or type construction
return v8::StringObject::New(value).As<v8::StringObject>();
~~~~~~~~~~~~~~~~^
../../../../nan/nan_implementation_12_inl.h:337:60: error: expected expression
return v8::StringObject::New(value).As<v8::StringObject>();
^
In file included from ../fsevents.cc:6:
../../../../nan/nan.h:1063:44: error: no matching member function for call to 'ToString'
v8::Local<v8::String> string = from->ToString();
~~~~~~^~~~~~~~
/Users/rene/.node-gyp/12.1.0/include/node/v8.h:2528:44: note: candidate function not viable: requires single argument 'context', but no arguments were provided
V8_WARN_UNUSED_RESULT MaybeLocal<String> ToString(
^
/Users/rene/.node-gyp/12.1.0/include/node/v8.h:2544:35: note: candidate function not viable: requires single argument 'isolate', but no arguments were provided
Local<String> ToString(Isolate* isolate) const);
^
In file included from ../fsevents.cc:6:
...

阅读全文 »

前端开发中常见问题合集

1. 使用better-scroll插件时的一些问题

  1. 使用scrollInit初始化滑动容器,然后异步请求接口数据时直接赋值容器不能滑动,这是因为scroll在初始化时列表数据为空导致滚动容器高度为0,请求完数据scroll组件并不知道,所以需要手动刷新容器
解决代码如下:
1
2
3
4
5
6
// 异步加载的数据,手动刷新容器
var arr = await getData();
this.list = arr;
this.$nextTick(() => {
this.scroll.refresh();
});
注意!

this.list为你遍历的列表数据,
this.scroll为你的滚动容器,
this.scroll.refresh();必须放在dom加载完在执行,此处已vue为例写在this.$nextTick的回调中

spug配置前端自动化发布

1. 先ssh连接服务器

1
ssh root@服务器地址

2. 进入到登录用户系统目录下

1
cd ~

3. 创建一个名为spug的文件夹

1
mkdir spug

4. 创建docker-compose.yml

1
vi docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
version: "3.3"
services:
db:
image: mariadb:10.8.2
container_name: spug-db
restart: always
command: --port 3306 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
volumes:
- /data/spug/mysql:/var/lib/mysql
environment:
- MYSQL_DATABASE=spug
- MYSQL_USER=spug
- MYSQL_PASSWORD=spug.cc
- MYSQL_ROOT_PASSWORD=spug.cc
spug:
image: openspug/spug-service
container_name: spug
privileged: true
restart: always
volumes:
- /data/spug/service:/data/spug
- /data/spug/repos:/data/repos
ports:
# 如果80端口被占用可替换为其他端口,例如: - "8000:80"
- "80:80"
environment:
- MYSQL_DATABASE=spug
- MYSQL_USER=spug
- MYSQL_PASSWORD=spug.cc
- MYSQL_HOST=db
- MYSQL_PORT=3306
depends_on:
- db

5. 创建docker-compose.yml

1
vi docker-compose.yml

6. 启动容器

1
docker compose up -d

7. 初始化spug

以下操作会创建一个用户名为 admin 密码为 123456 的管理员账户,可自行替换管理员账户/密码。

1
docker exec spug init_spug admin 123456

不出意外此时已经安装好spug了

阅读全文 »

flutter运行时卡住的解决办法

flutter run 运行时会卡在Running ‘gradle assembleDebug, 因为Gradle的Maven仓库在国外, 我们可以使用阿里云的镜像地址。


解决方法:

修改项目中android/build.gradle文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
// 修改注释的地方换成下面阿里云的镜像地址便可解决问题
// google()
// mavenCentral()
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
0%