严格模式
不是必须的 他就是一种写代码的规范提示 提示如果修改vuex的state不是由mutations修改的就会提示错误
严格模式下,无论何时发生了状态变更且不是由 mutation 函数引起的,将会抛出错误。这能保证所有的状态变更都能被调试工具跟踪到。
开启严格模式,仅需在创建 store 的时候传入 strict: true
Mixins 混入
混入就是vue中的一个复用技巧 他可以复用组件中的属性方法 便于其他组件复用
局部混入:
1.创建 创建文件夹与文件用来存放代码 写入如下内容
let ma={
data(){
return{
matext:"我是混入的变量"
}
},
methods:{
mafun(){
console.log("我是混入的方法")
}
}
}
export default ma
2.引用 调用 使用
<template>
<div class="home">
<img alt="Vue logo" src="../assets/logo.png">
<!-- 3.使用 -->
<h1>{{matext}}</h1>
<button @click="mafun()">都点我</button>
</div>
</template>
<script>
// 1引用
import ma from "@/mixins/ma.js"
export default {
name: 'Home',
components: {
},
// 2.调用
mixins:[ma]
}
</script>
全局混入 了解即可 不要用 因为会污染整个代码
在任何组件中都可以使用
在main中引用 并且使用
import MinXin from ‘@/components/MinXins/index.js’
Vue.mixin(MinXin);
在组件中即可随意使用混入中的数据