5月31
1.引入generator支撑库
经过Babel转译后的代码,会把aysnc/await的功能通过类似co库的方式来实现,即要使用到generator,所以,和我们使用co的时候一样,需要依赖一个regeneratorRuntime,才能支持generator特性。我们可以使用Facebook开源的regenerator库。你可以通过npm来下载这个regenerator库:
npm install regenerator --save
然后将下载文件中名为regenerator-runtime的文件拿出来,放到我们的小程序代码中去。
2.引入代码
在需要使用async/await特性的代码文件中,引入regenerator库:
import regeneratorRuntime from '../../utils/regenerator-runtime/runtime-module.js';
然后,你就可以放心的在你的代码里使用async/await来写异步处理了。
经过Babel转译后的代码,会把aysnc/await的功能通过类似co库的方式来实现,即要使用到generator,所以,和我们使用co的时候一样,需要依赖一个regeneratorRuntime,才能支持generator特性。我们可以使用Facebook开源的regenerator库。你可以通过npm来下载这个regenerator库:
npm install regenerator --save
然后将下载文件中名为regenerator-runtime的文件拿出来,放到我们的小程序代码中去。
2.引入代码
在需要使用async/await特性的代码文件中,引入regenerator库:
import regeneratorRuntime from '../../utils/regenerator-runtime/runtime-module.js';
然后,你就可以放心的在你的代码里使用async/await来写异步处理了。
5月30
5月30
[codes=c#]
download: function() {
console.log("xiazai")
var obj = document.getElementById('download');
var str = "姓名,出生日期,地址\n";
for (var i = 0; i < this.tableData.length; i++) {
var item = this.tableData[i];
str += item.name + ',' + item.date + ',' + item.address;
str += "\n";
}
console.log(obj)
str = encodeURIComponent(str);
console.log(str)
obj.href = "data:text/csv;charset=utf-8,\ufeff" + str;
obj.download = "download.csv";
}
[/codes]>
download: function() {
console.log("xiazai")
var obj = document.getElementById('download');
var str = "姓名,出生日期,地址\n";
for (var i = 0; i < this.tableData.length; i++) {
var item = this.tableData[i];
str += item.name + ',' + item.date + ',' + item.address;
str += "\n";
}
console.log(obj)
str = encodeURIComponent(str);
console.log(str)
obj.href = "data:text/csv;charset=utf-8,\ufeff" + str;
obj.download = "download.csv";
}
[/codes]>
5月30
[codes=c#]
file upload
【注意,参数传的是这个input的html元素,若是jquery,此参数是$('#file')[0]】
[/codes]!doctype>
【注意,参数传的是这个input的html元素,若是jquery,此参数是$('#file')[0]】
[/codes]!doctype>
5月30
$mount()手动挂载
当Vue实例没有el属性时,则该实例尚没有挂载到某个dom中;
假如需要延迟挂载,可以在之后手动调用vm.$mount()方法来挂载。例如:
[codes=c#]
new Vue({
//el: '#app',
router,
render: h => h(App)
// render: x => x(App)
// 这里的render: x => x(App)是es6的写法
// 转换过来就是: 暂且可理解为是渲染App组件
// render:(function(x){
// return x(App);
// });
}).$mount("#app");
[/codes]
或者
[codes=c#]
new Vue({
el: '#app',
router,
render: h => h(App)
// render: x => x(App)
// 这里的render: x => x(App)是es6的写法
// 转换过来就是: 暂且可理解为是渲染App组件
// render:(function(x){
// return x(App);
// });
});
[/codes]
当Vue实例没有el属性时,则该实例尚没有挂载到某个dom中;
假如需要延迟挂载,可以在之后手动调用vm.$mount()方法来挂载。例如:
[codes=c#]
new Vue({
//el: '#app',
router,
render: h => h(App)
// render: x => x(App)
// 这里的render: x => x(App)是es6的写法
// 转换过来就是: 暂且可理解为是渲染App组件
// render:(function(x){
// return x(App);
// });
}).$mount("#app");
[/codes]
或者
[codes=c#]
new Vue({
el: '#app',
router,
render: h => h(App)
// render: x => x(App)
// 这里的render: x => x(App)是es6的写法
// 转换过来就是: 暂且可理解为是渲染App组件
// render:(function(x){
// return x(App);
// });
});
[/codes]
5月29
按官网
[codes=c#]
import Vant from 'vant';
import 'vant/lib/vant-css/index.css';
Vue.use(Vant);
[/codes]
报错
Vant is not defined
按需引入后解决
[codes=c#]
import { Button } from 'vant';
Vue.use(Button);
[/codes]
问题:
见官方文档https://youzan.github.io/vant/#/zh-CN/quickstart “快速上手--方式三”,另外github的基于step的说明的确很坑爹,已提交commit了
方式三. 导入所有组件
配置 babel-plugin-import 插件后将不允许导入所有组件的方式
[codes=c#]
import Vant from 'vant';
import 'vant/lib/vant-css/index.css';
Vue.use(Vant);
[/codes]
报错
Vant is not defined
按需引入后解决
[codes=c#]
import { Button } from 'vant';
Vue.use(Button);
[/codes]
问题:
见官方文档https://youzan.github.io/vant/#/zh-CN/quickstart “快速上手--方式三”,另外github的基于step的说明的确很坑爹,已提交commit了
方式三. 导入所有组件
配置 babel-plugin-import 插件后将不允许导入所有组件的方式
5月29
Vue 项目中使用 webpack 将多个组件合并打包并实现按需加载 https://segmentfault.com/a/1190000008376183
5月28
今天VUE的脚手架工具出问题了
[codes=c#]
ERROR Failed to compile with 2 errors 3:41:32 PM
error in ./src/components/HelloWorld.vue
Module build failed: Error: No parser and no file path given, couldn't infer a parser.
at UndefinedParserError.Wrapper (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:1948:14)
at new UndefinedParserError (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:2055:83)
at normalize (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:7051:13)
at formatWithCursor (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:10370:12)
at C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:31115:15
at Object.format (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:31134:12)
at Object.module.exports (C:\Users\Administrator\Desktop\vue\my-project\node_modules\vue-loader\lib\template-compiler\index.js:80:23)
@ ./src/components/HelloWorld.vue 11:0-366
@ ./src/router/index.js
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
error in ./src/App.vue
Module build failed: Error: No parser and no file path given, couldn't infer a parser.
at _construct (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:1928:21)
at UndefinedParserError.Wrapper (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:1948:14)
at new UndefinedParserError (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:2055:83)
at normalize (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:7051:13)
at formatWithCursor (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:10370:12)
at C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:31115:15
at Object.format (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:31134:12)
at Object.module.exports (C:\Users\Administrator\Desktop\vue\my-project\node_modules\vue-loader\lib\template-compiler\index.js:80:23)
@ ./src/App.vue 11:0-354
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
[/codes]
解决方法:
运行:
npm i prettier@~1.12.0
重新运行:
npm run dev
[codes=c#]
ERROR Failed to compile with 2 errors 3:41:32 PM
error in ./src/components/HelloWorld.vue
Module build failed: Error: No parser and no file path given, couldn't infer a parser.
at UndefinedParserError.Wrapper (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:1948:14)
at new UndefinedParserError (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:2055:83)
at normalize (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:7051:13)
at formatWithCursor (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:10370:12)
at C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:31115:15
at Object.format (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:31134:12)
at Object.module.exports (C:\Users\Administrator\Desktop\vue\my-project\node_modules\vue-loader\lib\template-compiler\index.js:80:23)
@ ./src/components/HelloWorld.vue 11:0-366
@ ./src/router/index.js
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
error in ./src/App.vue
Module build failed: Error: No parser and no file path given, couldn't infer a parser.
at _construct (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:1928:21)
at UndefinedParserError.Wrapper (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:1948:14)
at new UndefinedParserError (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:2055:83)
at normalize (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:7051:13)
at formatWithCursor (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:10370:12)
at C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:31115:15
at Object.format (C:\Users\Administrator\Desktop\vue\my-project\node_modules\prettier\index.js:31134:12)
at Object.module.exports (C:\Users\Administrator\Desktop\vue\my-project\node_modules\vue-loader\lib\template-compiler\index.js:80:23)
@ ./src/App.vue 11:0-354
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
[/codes]
解决方法:
运行:
npm i prettier@~1.12.0
重新运行:
npm run dev