最近我开始使用lint-staged我的前端构建工具链。当我检查有关它的文档时,我总是发现它的工作原理如下:
"husky": {
"hooks": {
"pre-commit": "lint-staged"
},
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx,json,css}": [
"prettier --write",
"eslint --fix src/",
"tslint --fix --project .",
"git add"
]
},
Run Code Online (Sandbox Code Playgroud)
您可以在链接中找到更多类似的用法:https : //github.com/okonet/lint-staged
我的困惑点是最后一个命令git add,它的目的是什么?
我的理解是lint-staged仅 git add在git commit. 所以不明白为什么我们需要再添加一个git add。
在我的Vue项目中,我模拟了一些用于下一步开发的数据。我已经将测试数据保存在json文件中。我的vue项目是使用Vue-Cli创建的典型项目,我的项目的结构如下:
My_project
build
config
data
service_general_info.json
node_modules
src
components
component-A
component-A.vue
Run Code Online (Sandbox Code Playgroud)
如您所见,所有文件夹最初都是由vue-cli创建的。然后创建一个新文件夹data,并将测试数据json文件放入其中。
我想通过axios库在组件内部的事件处理函数中读取数据,component-A如下所示:
methods: {
addData() {
console.log('add json data...');
axios.get('./../../data/service_general_info.json');
},
},
Run Code Online (Sandbox Code Playgroud)
我使用相对路径来定位目标文件,但返回404错误。那么如何正确设置路径呢?目前,我正在dev本地主机中运行该模式。
错误消息是: GET http://localhost:8080/data/service_general_info.json 404 (Not Found)
在我的项目中,有一个用例:用户单击一个按钮,然后将一些数据复制到剪贴板以进行下一步。
复制的数据与单击的按钮相关,并以组件状态存储。
我进行了一些搜索,找到了可能的解决方案,如下所示:
function copyToClipboard(text){
var dummy = document.createElement("input");
document.body.appendChild(dummy);
dummy.setAttribute('value', text);
dummy.select();
document.execCommand("copy");
document.body.removeChild(dummy);
}
Run Code Online (Sandbox Code Playgroud)
在某种程度上,我们需要创建一个虚拟元素,将复制的数据设置为虚拟元素并选择该元素,然后执行该execCommand(copy)方法。
是否可以在不创建虚拟元素的情况下做到这一点?我知道有一些关于剪贴板的react插件,但我只想使用香草javascript。谢谢
我用以下演示重现了这个问题:http : //jsfiddle.net/baoqger/deL0yuvg/9/
在我的项目中,我有一个自定义图标标记,我想在某些情况下旋转图标。
我在创建图标时添加了一个 claasname:
const uturnIcon = L.icon({
iconUrl: 'http://joshuafrazier.info/images/firefox.svg',
iconSize: [30, 30],
className: 'u-turn-icon'
})
Run Code Online (Sandbox Code Playgroud)
并为该类添加 css 样式,如下所示:
.u-turn-icon {
transform: rotate(20deg) !important
}
Run Code Online (Sandbox Code Playgroud)
问题是默认情况下,图标img有一个style属性transform: translate3d,所以默认的transform和我添加的transform样式有冲突。并且默认的变换样式是由传单本身创建的,当我们缩放地图时,该属性的值也会更新。
那么如何解决这个问题呢?
我打算绘制多列数据文件.用第1列和第i列绘制xy图.所以基于手册的工作命令.哪个gnuplot版本开始有这样的功能?我的机器安装版本4.2,但无法正常工作.对于columnheader()的同样问题,
我想确保它是我的代码问题或版本.
在我的 angular 项目中,我有一个服务,用于状态管理以在组件之间共享一些数据,如下所示:
@Injectable({ providedIn: "root"})
export class NameStateService {
private _filteredNames$: Subject<Name[]> = new Subject();
private _filteredNamesObs$: Observable<Name[]>;
constructor() {
this._filteredNamesObs$ = this._filteredNames$.asObservable();
}
public updateFilteredNames(val: Name[]): void {
this._filteredNames$.next(val);
}
public get filteredNames$(): Observable<BillingAccount[]> {
return this._filteredNamesObs$;
}
}
Run Code Online (Sandbox Code Playgroud)
状态管理基于主题和可观察,这是 rxjs 世界中的典型用法。
而对于这个服务的单元测试,我想使用rxjs/testing模块支持的弹珠测试功能。解决方法如下:
describe("Name state service ", () => {
let nameStateService: NameStateService;
let scheduler: TestScheduler;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
NameStateService
]
});
nameStateService = TestBed.get(NameStateService);
scheduler = new TestScheduler((actual, expected) => expect(actual).toEqual(expected));
}); …Run Code Online (Sandbox Code Playgroud) 在使用 的过程中react-redux,我遇到了一个关于 的混淆点mapDispatchToProps,当它是一个对象而不是函数时。
例如,在我的项目中,我有以下操作创建者:
export const incrementBy2 = () => ({
type: INCREMENT_REQUESTED_2,
})
Run Code Online (Sandbox Code Playgroud)
在我的组件中,我导入了 action creator 并为 mapDispatchToProps 设置了它:
import { incrementBy2 } from '../actions'
import { connect } from 'react-redux'
// define the Home component, omit the details
const Home = props => ()
// omit the details
const mapStateToProps = state => ()
const mapDispatchToProps = {
incrementBy2
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(Home)
Run Code Online (Sandbox Code Playgroud)
然后在组件中,我可以访问 action creator as props.incrementBy2,它在我的项目中也运行良好。
我的困惑点,incrementBy2 …
在以下链接中,有在线演示案例展示了如何使用 esri-leaflet-geosearch 插件,https: //codepen.io/exomark/pen/dafBD
var searchControl = new L.esri.Controls.Geosearch().addTo(map);
var results = new L.LayerGroup().addTo(map);
searchControl.on('results', function(data){
results.clearLayers();
for (var i = data.results.length - 1; i >= 0; i--) {
results.addLayer(L.marker(data.results[i].latlng));
}
});
Run Code Online (Sandbox Code Playgroud)
这个在线演示可以很好地支持地理搜索功能。
在我的 React 应用程序中,我还计划添加诸如用于传单的搜索框。但无法弄清楚如何做到这一点。
由于esri-leaflet-geosearch取决于esri-leaflet,所以安装了两个 npm 包,但找不到下一步。所以有什么帮助吗?
我目前正在学习Webgl,在下面的示例中,我对gl.COLOR_BUFFER_BIT的用法有一个令人困惑的点:
const canvas = document.querySelector("#glcanvas");
// Initialize the GL context
const gl = canvas.getContext("webgl");
// Only continue if WebGL is available and working
if (!gl) {
alert("Unable to initialize WebGL. Your browser or machine may not support it.");
return;
}
// Set clear color to black, fully opaque
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
console.log('1: ', gl.COLOR_BUFFER_BIT);
// Clear the color buffer with specified clear color
gl.clearColor(1, 1, 1, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
console.log('2: ', gl.COLOR_BUFFER_BIT);
Run Code Online (Sandbox Code Playgroud)
我的理解gl.clear(gl.COLOR_BUFFER_BIT)是将 的值设置gl.COLOR_BUFFER_BIT为 中设置的颜色 …
我exec和evalTcl 有点困惑.在以下示例中:
set cmd "mkdir new_folder";
exec $cmd
Run Code Online (Sandbox Code Playgroud)
不能与错误消息一起使用:couldn't execute "mkdir new_folder" no such file or directory.
并且eval有效
set cmd "mkdir new_folder";
eval exec $cmd
Run Code Online (Sandbox Code Playgroud)
我也尝试过这种方式:
set cmd_1 "mkdir";
set cmd_2 "new_folder"
exec $cmd_1 $cmd_2
Run Code Online (Sandbox Code Playgroud)
它也很好用.那是什么原因?
leaflet ×2
angular ×1
axios ×1
clipboard ×1
columnheader ×1
esri-leaflet ×1
eval ×1
exec ×1
for-loop ×1
git ×1
gnuplot ×1
icons ×1
javascript ×1
json ×1
lint ×1
lint-staged ×1
marker ×1
react-redux ×1
reactjs ×1
redux ×1
rxjs ×1
rxjs-marbles ×1
tcl ×1
transform ×1
unit-testing ×1
vue.js ×1
webgl ×1