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

公司注册网站方法十大推广app平台

公司注册网站方法,十大推广app平台,赣州章贡疫情最新情况今天,wordpress ping文章目录 一、 什么是pinia二、 创建空Vue项目并安装Pinia1. 创建空Vue项目2. 安装Pinia并注册 三、 实现counter四、 实现getters五、 异步action六、 storeToRefs保持响应式解构七、基本使用:【1】main.js【2】store》index.js【3】member.ts 一、 什么是pinia P…

文章目录

    • 一、 什么是pinia
    • 二、 创建空Vue项目并安装Pinia
      • 1. 创建空Vue项目
      • 2. 安装Pinia并注册
    • 三、 实现counter
    • 四、 实现getters
    • 五、 异步action
    • 六、 storeToRefs保持响应式解构
    • 七、基本使用:
            • 【1】main.js
            • 【2】store=》index.js
            • 【3】member.ts


一、 什么是pinia

Pinia 是 Vue 的专属状态管理库,可以实现跨组件或页面共享状态,是 vuex 状态管理工具的替代品,和 Vuex相比,具备以下优势

  1. 提供更加简单的API (去掉了 mutation )
  2. 提供符合组合式API风格的API (和 Vue3 新语法统一)
  3. 去掉了modules的概念,每一个store都是一个独立的模块
  4. 搭配 TypeScript 一起使用提供可靠的类型推断

二、 创建空Vue项目并安装Pinia

1. 创建空Vue项目

npm init vue@latest

2. 安装Pinia并注册

npm i pinia
import { createPinia } from 'pinia'const app = createApp(App)
// 以插件的形式注册
app.use(createPinia())
app.use(router)
app.mount('#app')

三、 实现counter

核心步骤:

  1. 定义store
  2. 组件使用store

1- 定义store

import { defineStore } from 'pinia'
import { ref } from 'vue'export const useCounterStore = defineStore('counter', ()=>{// 数据 (state)const count = ref(0)// 修改数据的方法 (action)const increment = ()=>{count.value++}// 以对象形式返回return {count,increment}
})

2- 组件使用store

<script setup>// 1. 导入use方法import { useCounterStore } from '@/stores/counter'// 2. 执行方法得到store store里有数据和方法const counterStore = useCounterStore()
</script><template><button @click="counterStore.increment">{{ counterStore.count }}</button>
</template>

四、 实现getters

getters直接使用计算属性即可实现

// 数据(state)
const count = ref(0)
// getter (computed)
const doubleCount = computed(() => count.value * 2)

五、 异步action

思想:action函数既支持同步也支持异步,和在组件中发送网络请求写法保持一致
步骤:

  1. store中定义action
  2. 组件中触发action

1- store中定义action

const API_URL = 'http://geek.itheima.net/v1_0/channels'export const useCounterStore = defineStore('counter', ()=>{// 数据const list = ref([])// 异步actionconst loadList = async ()=>{const res = await axios.get(API_URL)list.value = res.data.data.channels}return {list,loadList}
})

2- 组件中调用action

<script setup>import { useCounterStore } from '@/stores/counter'const counterStore = useCounterStore()// 调用异步actioncounterStore.loadList()
</script><template><ul><li v-for="item in counterStore.list" :key="item.id">{{ item.name }}</li></ul>
</template>

六、 storeToRefs保持响应式解构

直接基于store进行解构赋值,响应式数据(state和getter)会丢失响应式特性,使用storeToRefs辅助保持响应式

<script setup>import { storeToRefs } from 'pinia'import { useCounterStore } from '@/stores/counter'const counterStore = useCounterStore()// 使用它storeToRefs包裹之后解构保持响应式const { count } = storeToRefs(counterStore)const { increment } = counterStore</script><template><button @click="increment">{{ count }}</button>
</template>

七、基本使用:

【1】main.js
import { createSSRApp } from 'vue'
import App from './App.vue'// 导入 pinia 实例
import pinia from './stores'
import persist from 'pinia-plugin-persistedstate'
// 使用持久化存储插件
pinia.use(persist)export function createApp() {// 创建 vue 实例const app = createSSRApp(App)// 使用 piniaapp.use(pinia)return {app,}
}

在这里插入图片描述

【2】store=》index.js
import { createPinia } from 'pinia'// 创建 pinia 实例
const pinia = createPinia()// 默认导出,给 main.ts 使用
export default pinia

在这里插入图片描述

【3】member.ts
import type { LoginResult } from '@/types/member'
import { defineStore } from 'pinia'
import { ref } from 'vue'// 定义 Store
export const useMemberStore = defineStore('member',() => {// 会员信息const profile = ref<LoginResult>()// 保存会员信息,登录时使用const setProfile = (val: LoginResult) => {profile.value = val}// 清理会员信息,退出时使用const clearProfile = () => {profile.value = undefined}// 记得 returnreturn {profile,setProfile,clearProfile,}},{// 网页端配置// persist: true,// 小程序端配置persist: {storage: {getItem(key) {return uni.getStorageSync(key)},setItem(key, value) {uni.setStorageSync(key, value)},},},},
)

在这里插入图片描述

http://www.dinnco.com/news/39003.html

相关文章:

  • 广西住房和城乡建设厅网站证件百度推广登陆平台
  • 网站开发相关的教材书籍如何申请一个网站域名
  • 网站服务器出错了怎么办百度点击优化
  • yum wordpress php扩展宁波seo网络推广咨询价格
  • 做策划常用的网站google官网入口
  • 建网站怎么挣钱php开源建站系统
  • 163邮箱注册申请注册官网windows优化大师可靠吗
  • 深圳住建网站网红营销
  • 哪家网站建设公司好网站收录服务
  • 视频收费网站怎么做百度竞价恶意点击软件
  • 学做网站要编程淘宝搜索排名
  • 做网站专题怎样添加微博怎样通过网络销售自己的产品
  • 网站开发程序说明百度手机端排名
  • PHP网站开发工程师快抖霸屏乐云seo
  • wikidot怎么建设网站谷歌搜索引擎网页版入口
  • 手表网站 美国北京朝阳区优化
  • 济宁城乡建设委员会的网站百度快速排名工具
  • 莱芜金点子司机在线招聘信息西安seo服务
  • 网站建设分金手指专业十九站长工具介绍
  • 网上发布信息的网站怎么做的青岛关键词网站排名
  • 英国政府网站建设的总结广州新闻播报
  • 专业定制家具厂家乐陵seo外包
  • wordpress链接调用seo推广是做什么的
  • 龙华企业网站建设公司杭州网站seo推广
  • 电商数据网站seo网站推广服务
  • 织梦做网站也是模板吗设计网站接单
  • 合肥关键词排名提升网站推广优化设计方案
  • 用织梦做模板网站网站运营
  • web网站开发用到的技术怎么在百度上发布信息
  • 创新网站内容建设神马seo服务