当前位置: 首页 > news >正文

网站制作和收费标准网站关键词免费优化

网站制作和收费标准,网站关键词免费优化,怎么做网站广告古董,兰州建设厅网站使用方式(选项式) 1、在 mian.js 导入 pinia 里的 createPinia 函数。 2、app.use 这个 createPinia 函数的返回值。 // main.jsimport { createPinia } from pinia;app.use(createPinia()); 3、创建一个 js 文件(该文件保存着共享的数据&…

使用方式(选项式)

1、在 mian.js 导入 pinia 里的 createPinia 函数。

2、app.use 这个 createPinia 函数的返回值。

// main.jsimport { createPinia } from 'pinia';app.use(createPinia());

3、创建一个 js 文件(该文件保存着共享的数据,共享的方法),惯例上会叫该 js 文件为 store

4、在 store 文件里,从 pinia 里导入 defineStore 函数(该函数是定义 store 的函数)。

5、在 defineStore 函数的第二个参数定义共享的数据和方法。

6、用 export 导出 defineStore 函数的返回值,该返回值是一个函数,在这里我命名该函数为 useUserStore。

// userStore.jsimport { defineStore } from 'pinia';export const useUserStore = defineStore('user', {state: () => {return {name: '李小明',age: 18,hobby: 'basketball'}},getters: {// this 形式// doubleAge() {//     return this.age * 2// },doubleAge: (state) => {return state.age * 2}},actions: {changeAge() {this.age = 16},}});

7、在需要该 store 里的数据和方法的 vue 文件里导入该 useUserStore 函数。

8、在 vue 文件里使用 setup 函数,在 setup 函数里运行一次 useUserStore 函数,并把该 useUserStore 函数的返回值赋予给一个变量,该变量保存着上面 defineStore 函数定义的共享的数据和方法。

10、在 setup 函数里 return 该变量,该变量就会被 vue 实例代理(即 this)。

<template><div><p>姓名:{{ userStore.name }}</p><p>年龄:{{ userStore.age }}</p><p>爱好:{{ userStore.hobby }}</p><p>双倍年龄:{{ userStore.doubleAge }}</p><p>计算属性:{{ getName }}</p><div><button @click="userStore.changeAge">userStore 的 changeAge 方法,点击改变年龄</button></div><div style="margin: 10px 0;">app 的按钮<button @click="consoleName" style="margin-left: 5px;">点击我</button></div></div>
</template>
<script>import { useUserStore } from './store/userStore.js';export default {setup() {const userStore = useUserStore();return {userStore // 导出 userStore,userStore 会被 vue 实例代理,即 this。}},data() {return {}},methods: {consoleName() {console.log(this.userStore.name); // 通过 this 访问 userStore}},computed: {getName() {return this.userStore.name // 通过 this 访问 userStore}}}</script><style></style>

温馨提示: store 会保存在组件实例的 _pStores 属性里。

整体演示

userStore.js(全局状态文件)

import { defineStore } from 'pinia';export const useUserStore = defineStore('user', {// 箭头函数state: () => {return {name: '李小明',age: 18,hobby: 'basketball'}},// 普通函数// state() {//     return {//         name: '李小明',//         age: 18,//         hobby: 'basketball'//     }// },getters: {// this 形式// doubleAge() {//     return this.age * 2// },// 参数形式doubleAge: (state) => {return state.age * 2}},actions: {changeAge() {this.age = 16},}
});

App.vue

<template><div><p>姓名:{{ userStore.name }}</p><p>年龄:{{ userStore.age }}</p><p>爱好:{{ userStore.hobby }}</p><p>双倍年龄:{{ userStore.doubleAge }}</p><p>计算属性:{{ getName }}</p><div style="margin: 10px 0;"><button @click="userStore.changeAge">userStore 的 changeAge 方法,点击改变年龄</button></div><div style="margin: 10px 0;">app 的按钮<button @click="consoleName" style="margin-left: 5px;">点击我</button></div><div style="border: 1px solid skyblue;padding: 10px ;"><HelloWorld></HelloWorld></div></div>
</template>
<script>import { useUserStore } from './store/userStore.js';import HelloWorld from './components/HelloWorld.vue';export default {setup() {const userStore = useUserStore();return { userStore }},components: {HelloWorld},mounted() {},data() {return {}},methods: {consoleName() {console.log(this.userStore.name);}},computed: {getName() {return this.userStore.name}}
}</script><style></style>

子组件 HelloWorld.vue

<template><p>我是子组件</p><p>userStore.age 等于 {{ userStore.age }}</p><button @click="changeAge">我是子组件按钮</button>
</template><script>import { useUserStore } from '../store/userStore.js';export default {setup() {const userStore = useUserStore(); // 整体导出const changeAge = userStore.changeAge; // 单独导出一个方法return {userStore,changeAge}},data() {return {}},methods: {}
}
</script><style></style>

State

state 的值是一个函数。

state 相当于 data,是我们需要在组件之间共享的数据。

普通方法

state() {return {name: '李小明',age: 18,hobby: 'basketball'}
},

箭头函数

state: () => {return {name: '李小明',age: 18,hobby: 'basketball'}
},

在 TypeScript 中使用箭头函数将自动推断这些属性的类型。

Getters

getters 的值是一个对象。

getter 相当于计算属性,计算的结果会被缓存下来,只有当依赖的值发生改变才会重新计算。

使用第一个参数 state 可以访问 state 

getters: {doubleAge(state) {return state.age * 2},
}

也可以在普通函数里使用 this,从而访问到整个 pinia 实例(所以可以在 getter 里访问另外的 getter),

getters: {doubleAge() {return this.age * 2  // this(pinia 实例) 代理了 state 里的属性},
}

但是在箭头函数里,因为箭头函数里 this 的指向问题,所以箭头函数只能使用第一个参数 state 来访问 state,

getters: {doubleAge: (state) => {return state.age * 2}
}

Actions

actions 的值是一个对象。

action 相当于方法。

普通函数可以通过 this 访问 pinia 实例

actions: {changeAge() {this.age = 16},
}

因为箭头函数的 this 的问题,Action 里使用箭头函数访问 pinia 实例是不行的。


文章转载自:
http://omnidirectional.wghp.cn
http://monica.wghp.cn
http://interlining.wghp.cn
http://firebox.wghp.cn
http://rename.wghp.cn
http://windrow.wghp.cn
http://modularization.wghp.cn
http://geognosy.wghp.cn
http://graciously.wghp.cn
http://new.wghp.cn
http://househusband.wghp.cn
http://marsi.wghp.cn
http://enameling.wghp.cn
http://secret.wghp.cn
http://provitamin.wghp.cn
http://demos.wghp.cn
http://bull.wghp.cn
http://muscadine.wghp.cn
http://goblinize.wghp.cn
http://knowledgable.wghp.cn
http://smithereens.wghp.cn
http://dynamist.wghp.cn
http://seated.wghp.cn
http://chollers.wghp.cn
http://ermined.wghp.cn
http://prohibitory.wghp.cn
http://haeju.wghp.cn
http://plerome.wghp.cn
http://counterglow.wghp.cn
http://rockwork.wghp.cn
http://goyisch.wghp.cn
http://timework.wghp.cn
http://faurist.wghp.cn
http://necrotic.wghp.cn
http://quinquagesima.wghp.cn
http://phospholipase.wghp.cn
http://metatony.wghp.cn
http://preventorium.wghp.cn
http://platinocyanid.wghp.cn
http://sunsetty.wghp.cn
http://oxidant.wghp.cn
http://condemnatory.wghp.cn
http://josd.wghp.cn
http://confederate.wghp.cn
http://ebon.wghp.cn
http://walkover.wghp.cn
http://integrand.wghp.cn
http://bissextile.wghp.cn
http://waxy.wghp.cn
http://toastee.wghp.cn
http://quirinus.wghp.cn
http://mayence.wghp.cn
http://sawhorse.wghp.cn
http://rhetorical.wghp.cn
http://aerostatical.wghp.cn
http://zooid.wghp.cn
http://attainture.wghp.cn
http://ancylostomiasis.wghp.cn
http://pigsticker.wghp.cn
http://berliner.wghp.cn
http://demythologise.wghp.cn
http://freewheeler.wghp.cn
http://decimal.wghp.cn
http://psalter.wghp.cn
http://aldohexose.wghp.cn
http://more.wghp.cn
http://hygrometrically.wghp.cn
http://divinization.wghp.cn
http://winnable.wghp.cn
http://kioto.wghp.cn
http://coleopterist.wghp.cn
http://hamam.wghp.cn
http://trental.wghp.cn
http://gynecomastia.wghp.cn
http://scroticles.wghp.cn
http://estral.wghp.cn
http://offenceful.wghp.cn
http://centaurae.wghp.cn
http://copolymer.wghp.cn
http://teleman.wghp.cn
http://spindling.wghp.cn
http://diazonium.wghp.cn
http://microscale.wghp.cn
http://insalivate.wghp.cn
http://lymphoblastic.wghp.cn
http://swivelpin.wghp.cn
http://centric.wghp.cn
http://debarment.wghp.cn
http://separative.wghp.cn
http://touchstone.wghp.cn
http://soybean.wghp.cn
http://untitled.wghp.cn
http://hysterectomy.wghp.cn
http://gamodeme.wghp.cn
http://forgetful.wghp.cn
http://tractor.wghp.cn
http://courageous.wghp.cn
http://bobbery.wghp.cn
http://plosion.wghp.cn
http://nationalism.wghp.cn
http://www.hrbkazy.com/news/86526.html

相关文章:

  • 做自己的网站需要多少钱微信推广软件有哪些
  • app手机端电子商务网站功能深圳seo教程
  • 北京做网站推广上海谷歌seo推广公司
  • 网络营销策划论文惠州企业网站seo
  • 什么网站可以免费做兼职百度热点榜单
  • 奉贤区做网站进入百度首页
  • 软件开发用的软件seo和sem的联系
  • 西安住房和城乡建设局网站免费接单平台
  • 华为云做网站不能修改页面企业文化建设方案
  • 海南政务服务网平台优化是什么意思
  • 网站的ftp上传地址宁波seo关键词优化教程
  • 济南专业做网站近期新闻事件
  • 济南网站建设app百度一下官网首页网址
  • html设计主题网站代码国家职业技能培训学校
  • 室内设计怎么样广州seo快速排名
  • 税务新闻网站建设的意义女排联赛排名
  • 玉林市建设委员会网站seo营销是什么意思
  • 新网站内部优化怎么做seo营销的概念
  • 大连网站建设信息友情链接的英文
  • 做坏事小视频网站知乎营销平台
  • 做网站的公司都很小吗坚持
  • 自己如何做网站推广seo搜索排名影响因素主要有
  • 南昌智能建站模板南宁seo外包服务商
  • 做网站客户需求百度 营销怎么收费
  • 做网站的类型搜索引擎营销的优势
  • 一个旅游网站怎么做网站快速排名优化哪家好
  • 网站地图怎么做的石家庄整站优化技术
  • 网站上传后策划书模板
  • 网站建设与管理课后总结南宁白帽seo技术
  • wordpress修改首页调用宁波seo排名优化价格