关于本站
“最难不过坚持”
本人承接扒站仿站,php网站维护,病毒查杀,网站编辑,网站改版,html制作
有需要网站维护,改版,病毒查杀,网站编辑,网站备案,html制作等相关的工作可以联系我。
本人有多年相关工作经验,也可提供免费咨询,交个朋友。
有需要探讨问题的朋友,也可以加我微信,共同探讨!
微信:15011482830 QQ:408917339
2712
39
分类目录
最新评论
- https://jueru.net/
-
评 留言
- :weixiao:
-
评 留言
- :shuijiao: :weiqu: :zhenbang: :leng:
-
评 留言
- :yiwen: :yiwen: :yiwen: :yiwen:
-
评 EasySass: could not generate CSS file. See Output panel for details.
- 这个业务逻辑多少都有点奇怪了,阅读浏览次数增值在新闻详情页的控制器方法里setInc,这怎么还写进模型事件里了。如果非要用onAfterRead也可以,把新闻文章的内容单独分出来一个news_content表,然后把它和news做关联,然后给news_content表的onAfterRead事件做增值处理,这样点进新闻页内查询到文章内容时才会触发它。
-
评 TP6模型事件-查询后onAfterRead不好用
文章标签更多
Vuex的基本使用:
1、初始化数据 state,配置actions、mutations,操作文件store.js2、组件中读取 vuex 中的数据 $store.state.数据
3、组件中修改 vuex 中的数据 $store.dispatch('action中的方法名', 数据)
或 $store.commit('大写方法名', 数据)
若没有网络请求或其他业务逻辑,组件中也可越过actions,即不写dispatch,直接编写commit
案例注意点 vuex 的引入是在src/store/index.js 中
然后就是对于没有逻辑的方法, 就可以直接在组件方法调用 commit 去直接连接 mutations:this.$state.commit('大写方法名', 数据)
对那些需要逻辑判断定时器, 需要发送 ajax 请求的都需要在组件方法调用 dispatch 去连接 actions 在 actions 里面进行逻辑的判断和 ajax 请求的发送,:this.$state.dispatch('action中的方法名', 数据)。
main.js
import Vue from 'vue'
import App from './App.vue'
import store from './store/index'
Vue.config.productionTip = false
new Vue({
render: h => h(App),
store
}).$mount('#app')
src/store/index.js该文件用于创建Vuex中最为核心的store
//引入Vue核心库
import Vue from 'vue'
//引入 Vuex
import Vuex from 'vuex'
//应用vuex插件
Vue.use(Vuex)
//准备actions对象---响应组件中用户的动作
const actions = {
conditionSum (context, value) {
if (context.state.sum % 2 == 1) {
context.commit('CONDITIONSUM', value)
}
},
waitSum (context, value) {
setTimeout(() => {
context.commit('WAITSUM', value)
}, 1000);
}
}
//准备mutation对象---修改state中的数据
const mutations = {
ADDSUM (state, value) {
state.sum += value
},
SUBTRACTSUM (state, value) {
state.sum -= value
},
CONDITIONSUM (state, value) {
state.sum += value
},
WAITSUM (state, value) {
state.sum += value
}
}
//准备state对象---保存具体的数据
const state = {
sum: 0
}
//创建并暴露store
export default new Vuex.Store({
actions,
mutations,
state
})
Count.vue
<template>
<div>
<h1>加减求和的值为{{ $store.state.sum }}</h1>
<select v-model="number">
<option :value="1">1</option>
<option :value="2">2</option>
<option :value="3">3</option>
</select>
<button @click="addSum">+</button>
<button @click="subtractSum">-</button>
<button @click="conditionSum">和为奇数才能求和</button>
<button @click="waitSum">等一秒才进行求和</button>
</div>
</template>
<script>
export default {
name: "Count",
data() {
return {
number: 1,
};
},
methods: {
addSum() {
this.$store.commit("ADDSUM", this.number);
},
subtractSum() {
this.$store.commit("SUBTRACTSUM", this.number);
},
conditionSum() {
this.$store.dispatch("conditionSum", this.number);
},
waitSum() {
this.$store.dispatch("waitSum", this.number);
},
},
};
</script>
<style scoped>
button {
margin-left: 5px;
}
</style>
赏
相关推荐
接口返回request failed with status code 500错误
接口返回request failed with status code 500错误
登录界面,验证账号密码成功,但是返回500错误
可能原因:linux服务器,用tp5搭建的后台及接口,会生成一部分缓存文件,但是linux默认没有权限创建数据,所以,只要在缓存文件夹runtime添加写的权限即可
解决errors and 0 warnings potentially fixable with the `--fix` option.问题
解决errors and 0 warnings potentially fixable with the `--fix` option.问题
项目正常运行,就是有这个提示
找到.eslintrc.js注释掉// 'eslint:recommended'
评论加载中...