vue

[vue]使用webpack打包

只愿长相守 提交于 2020-02-17 08:15:31
使用webpack打包 hello.js暴露方法 exports.hello = function () { document.write("<h1>hello</h1>"); } main.js入口 var hello = require("./hello"); hello.hello(); webpack.config.js打包配置 module.exports = { entry: './modules/main.js', output: { filename: './js/bundle.js' } }; 生成的bundle.js !function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object

关于mapState和mapMutations和mapGetters 和mapActions辅助函数的用法及作用(二)-----mapMutations

不羁岁月 提交于 2020-02-17 07:46:01
在组件中提交 Mutations: import { mapState, mapMutations } from 'vuex' export default { data() { return { msg: "vuex要点" } }, store, computed: mapState([ 'count' ]), // methods: mapMutations([ // 'add', 'reduce' // ]), //或者 methods: { //如果组件中事件的名称和mutations中方法的名称相同,可以传一个字符串数组 ...mapMutations([ 'add' //映射 this.add() 为 this.$store.commit('add') ]), //组件中的事件名和mutations中的方法名不一样,传入对象 ...mapMutations({ reduces: 'reduce' //映射 $this.reduces 为 this.store.commit('reduce') }) } } Mutations必须是同步函数!!! 来源: https://www.cnblogs.com/lhl66/p/8261719.html

vue vuex

本秂侑毒 提交于 2020-02-17 07:11:01
安装:npm install --save vuex 在mian.js中 import Vuex from 'vuex'; Vue.use(Vuex); import store from './store/index'; 在new Vue({ })中加入 store:store, //注入到vue 在src文件夹中新建store文件夹 在新建的store文件夹中新建index.js和modules文件夹 在index.js中写入 import Vue from 'vue'; import Vuex from 'vuex'; Vue.use(Vuex); import list from "./modules/list";//(可以引入多个,在下面modules中在引用一下) export default new Vuex.Store({ modules:{ list:list } }) 在新建的modules文件夹中新建list.js 在index.js中写入 const state={ title:"sxl" } export default{ state } 在vue文件中引用{{$store.state.list.title}} 来源: https://www.cnblogs.com/zzg02/p/9312084.html

关于Vue中 render: h => h(App) 的具体含义的理解

与世无争的帅哥 提交于 2020-02-17 06:55:48
ps: 如果有任何问题可以评论留言,我看到后会及时解答,评论或关注,您的鼓励是我分享的最大动力 转载请注明出处: https://blog.csdn.net/qq_40938301/article/details/104342113 一、问题: https://github.com/vuejs-templates/webpack-simple/blob/master/template/src/main.js import Vue from 'vue' import App from './App.vue' new Vue({ el: '#app', render: h => h(App) }) vue的代码中有这么一段,令人第一眼对这个 h 函数十分困惑?? 二、原因: render: h => h(App) 是下面内容的缩写: render: function (createElement) { return createElement(App); } 进一步缩写为(ES6 语法): render (createElement) { return createElement(App); } 再进一步缩写为: render (h){ return h(App); } 按照 ES6 箭头函数的写法,就得到了: render: h => h(App); 其中 根据 Vue.js 作者

vuex mapGetters

懵懂的女人 提交于 2020-02-17 06:36:18
1、vuex 配置 //vuex的配置 //注意Store是大写 const store = new Vuex.Store({ //数据保存 state: { show: false, count: 0, list: [1, 5, 8, 10, 30, 50] }, mutations: { increase(state, n = 1) { state.count += n; }, decrease(state, n = 1) { state.count -= n; }, switch_dialog (state) { // 这里的state对应着上面这个state state.show = state.show ? false : true // 你还可以在这里执行其他的操作改变state } }, getters: { filteredList: state => { return state.list.filter(item => item < 31); } }, actions:{ asyncIncrease(context){ context.commit('increase'); }, switch_dialog123 (context) { // 这里的context和我们使用的$store拥有相同的对象和方法 context.commit('switch

vuex中的babel编译mapGetters/mapActions报错解决方法

青春壹個敷衍的年華 提交于 2020-02-17 06:34:54
vex使用...mapActions报错解决办法 vuex2增加了mapGetters和mapActions的方法,借助stage2的Object Rest Operator 所在通过 methods:{ ...mapActions([ 'increment' ]) } 酱紫去拿到action。但是我们需要安装babel-preset-stage-2的依赖。 可以使用babel插件, 该插件为 babel-plugin-transform-object-rest-spread 使用方法: npm install --save-dev babel-plugin-transform-object-rest-spread 新建.babelrc配置文件(切记不要忘记!!!) { "plugins": ["transform-object-rest-spread"] } 谢谢大家!!! 来源: https://www.cnblogs.com/maqingyuan/p/9284916.html

解决 vuex mapGetters 语法报错 (Unexpected token )

六月ゝ 毕业季﹏ 提交于 2020-02-17 06:34:39
在使用vuex2的mapGetters 和 mapActions 的方法时,借助 stage2 的 Object Rest Operator 特性,可以写出下面代码: computed: { ...mapGetters([ // … 三个点,在框架语言里,就是传对象 'hadChannels', 'currentChannel' ]) }    但是在借助babel编译转换时发生了报错: BabelLoaderError: SyntaxError: Unexpected token 。 搜索一番,结果是babel 没有解析成功,看来是 babel的配置为问题 原来的 .babelrc { "presets": [ ["env", { "modules": false, "targets": { "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] } }], "stage-2" ], "plugins": ["transform-vue-jsx", "transform-runtime"] }    解决方案 接着在babel的issues中搜索这样的报错,原来是我babel预置的转换器是 babel-preset-es2015 ,并不能转换 Object Rest Operator 特性。 1. 安装 Object Rest

vuex使用mapActions报错解决办法

家住魔仙堡 提交于 2020-02-17 06:33:43
先贴上报错: vuex2增加了mapGetters和mapActions的方法,借助stage2的Object Rest Operator 所在通过 methods:{ ...mapActions([ 'increment' ]) } 酱紫去拿到action。但是我们需要安装babel-preset-stage-2的依赖。 解决方案: 在package.js里面增加"babel-preset-stage-2": "^6.1.18", 然后npm i 安装依赖 接下来在.babelrc 配置 { "presets": [ ["es2015", { "modules": false }] ], "plugins": ["transform-object-rest-spread"] } 最后,我想说 从网上查阅资料得知babel-preset-stage-2中已包含babel-plugin-transform-object-rest-spread插件(es6的对象展开符插件),但是不知怎么还是没有解决此问题, 因此我在package.json里 npm install babel-plugin-transform-object-rest-spread --save dev, 我的项目中.babelrc文件是这样配置的: 然而,我却成功解决了此问题。。。 欢迎大神来告知一二!!! 来源:

Vuex的mapGetters方法使用报错

我的梦境 提交于 2020-02-17 06:33:30
报错信息: ERROR in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./app/components/header.vue Module build failed: SyntaxError: F:/web/tabs/app/components/header.vue: Unexpected token (32:7) 原因: 解决: npm isntall --save-dev babel-preset-stage-3    修改.babelrc配置 { "presets": ["es2015", "stage-3"] }    代码中 import {mapGetters} from 'vuex' export default { data(){ return { } }, computed:{ ...mapGetters([ 'isMain' ]) }, methods:{ } }    来源: https://www.cnblogs.com/laneyfu/p/11220674.html

vue之可变式函数

旧时模样 提交于 2020-02-17 06:17:19
当我们在vue之中,我们有时候需要传递好多参数的时候,我们往往需要在方法之中对写上对应数量的变量来接受参数,下面介绍一种简单的函数写法 < ! DOCTYPE html > < html lang = "en" > < head > < meta charset = "UTF-8" > < meta name = "viewport" content = "width=device-width, initial-scale=1.0" > < title > Document < / title > < / head > < script src = "../vue.js/vue.js" > < / script > < body > < div id = "app" > < ! -- < ul > < li v - for = "(item,index) in names" : key = "item" > { { index + 1 } } , { { item } } < / li > < / ul > -- > < ! -- 可变参数 -- > < / div > < script > const app = new Vue ( { el : '#app' , data : { names : [ 'a' , 'b' , 'c' ] } , methods : { } } )