当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript vuex.mapState函数代码示例

本文整理汇总了TypeScript中vuex.mapState函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mapState函数的具体用法?TypeScript mapState怎么用?TypeScript mapState使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了mapState函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: connectToComponent

    function connectToComponent(
      nameOrComponent: string | Component,
      optionalComponent?: Component
    ): Component {
      let Component: Component, name: string
      if (typeof nameOrComponent !== 'string') {
        Component = nameOrComponent
        name = getOptions(Component).name || 'wrapped-anonymous-component'
      } else {
        Component = optionalComponent!
        name = nameOrComponent
      }

      const propKeys = keys(
        stateToProps,
        gettersToProps,
        actionsToProps,
        mutationsToProps,
        methodsToProps
      )

      const eventKeys = keys(
        actionsToEvents,
        mutationsToEvents,
        methodsToEvents
      )

      const containerProps = omit(collectProps(Component), propKeys)
      const containerPropsKeys = Object.keys(containerProps)

      const options = {
        name: `connect-${name}`,
        props: containerProps,
        components: {
          [name]: Component
        },
        computed: merge(mapState(stateToProps), mapGetters(gettersToProps)),
        methods: merge(
          mapActions(merge(actionsToProps, actionsToEvents)),
          mapMutations(merge(mutationsToProps, mutationsToEvents)),
          mapValues(merge(methodsToProps, methodsToEvents), bindStore)
        )
      }

      insertLifecycleMixin(options, lifecycle)
      insertRenderer(
        options,
        name,
        propKeys.concat(containerPropsKeys),
        eventKeys
      )

      if (transform) {
        transform(options, lifecycle)
      }

      return typeof Component === 'function' ? Vue.extend(options) : options
    }
开发者ID:ktsn,项目名称:vuex-connect,代码行数:58,代码来源:connect.ts

示例2: createDetailablePage

export function createDetailablePage(isImplicit: boolean) {
  return {
    name: `${isImplicit ? 'implicit-' : ''}post-page`,
    computed: {
      ...mapState({
        date_format: (state: RootState) => state.meta.hexoConfig.dateTimeFormat.date_format,
        time_format: (state: RootState) => state.meta.hexoConfig.dateTimeFormat.time_format,
        target: (state: RootState) => state.detailable.target
      })
    },
    async fetch({ store, route }: Context) {
      const sourceOrSlug = isImplicit ? route.path.replace(/^\/pages\/?/, '') : route.params.slug;
      await store.dispatch(`detailable/${Fetch_Detailable_Target}`, { isImplicit, sourceOrSlug });
    },
    beforeRouteUpdate: async function (this: any, to, from, next) {
      const { fetch } = this.$options;
      if (fetch) {
        try {
          this.$nprogress.start();
          this.$data.search = '';
          await fetch({ store: this.$store, route: to });
          this.$nprogress.done();
        } catch (error) {
          next(error);
        }
      } else {
        next();
      }
    } as NavigationGuard,
    render(this: any, h: CreateElement) {
      return h(DetailablePage, {
        props: {
          isImplicit,
          date_format: this.date_format,
          time_format: this.time_format,
          target: this.target
        }
      });
    }
  };
}
开发者ID:Johnny-jiangli,项目名称:hexo-theme-lite,代码行数:41,代码来源:create-detailable.ts

示例3: editApi

          this.remove_apiList(currentId)
          this.isModify = false
        }
      }
    },
    async editApi(): Promise<any> {
      let { currentId, apiName, apiDesc } = this
      if( currentId && apiName && apiDesc ){
        let editParam: ITFetchApiList = {
          type: 'modify',
          id: currentId,
          name: apiName,
          desc: apiDesc
        }

        let removeState = await FETCH_API_LIST(editParam)
        if(removeState.ok === 1){
          this.modify_apiList({
            _id: currentId,
            name: apiName,
            desc: apiDesc
          })
          this.isModify = false
        }
      }
    }
  },
  computed: mapState([
    'apiList'
  ])
} as ComponentOptions<Modify>
开发者ID:jfengsky,项目名称:cquick,代码行数:31,代码来源:Modify.ts

示例4: newPath

// <router-link :to="/apiInfo?id={{item._id}}">{{item.name}}</router-link>
export default {
  template: `<div class="demo">
    <div v-for="item in apiList">
      <h4>{{item.name}} <b>{{item.desc}}</b></h4>
        <router-link :to="{path: newPath(item._id)}">{{item.name}}</router-link>
      <hr />
    </div>
    <router-view></router-view>
  </div>`,
  data(){
    return {
      message: 'Hello Message'
    }
  },
  components:{},
  methods:{
    onClick: function(): void {
      window.alert(this.message)
    },
    newPath: function(_id: string): string{
      return `/apiInfo?id=${_id}`
    }
  },
  computed: {
    ...mapState([
      'apiList'
    ])
    
  }
} as ComponentOptions<Api>
开发者ID:jfengsky,项目名称:cquick,代码行数:31,代码来源:Api.ts

示例5: fetchApiList

    ]),

    // 异步请求apiList
    async fetchApiList(){
      let fetchBack = await FETCH_API_LIST({
        type: 'search'
      })
      this.updata_apiList(fetchBack)
    },
    async fetchMockList(){
      let fetchMockBack = await FETCH_MOCK_LIST({
        type: 'search'
      })
      this.updata_mockList(fetchMockBack)
    },
    async fetchFileMockList(){
      let fetchMockBack = await FETCH_MOCK_CHANGE({
        type: 'search'
      })
      this.updata_fileMockList(fetchMockBack)
    }
  },
  // methods:{
  //   ...mapActions([
  //     'fetchApiList'
  //   ])
  // },
  computed: mapState([
    'routes'
  ])
} as ComponentOptions<Menu>
开发者ID:jfengsky,项目名称:cquick,代码行数:31,代码来源:Menu.ts

示例6: mounted

export default Vue.extend({
  name: 'gitment-comment',
  props: {
    isImplicit: {
      required: true,
      type: Boolean
    },
    slugOrSource: {
      required: true,
      type: String
    }
  },
  computed: {
    ...mapState({
      gitmentOptions: (state: RootState) => state.meta.themeConfig.gitment
    })
  },
  mounted() {
    if (!this.gitmentOptions.enable) {
      return;
    }

    // https://github.com/imsun/gitment#3-render-gitment
    const gitment = new Gitment({
      id: this.slugOrSource,
      owner: this.gitmentOptions.github_id,
      repo: this.gitmentOptions.repository_name,
      oauth: {
        client_id: this.gitmentOptions.client_id,
        client_secret: this.gitmentOptions.client_secret,
开发者ID:Johnny-jiangli,项目名称:hexo-theme-lite,代码行数:30,代码来源:gitment-comment.component.ts

示例7: deleteMock

      if(saveState.ok === 1){

        // 偷懒
        window.location.reload()
        // this.callback()
      }
    },
    async deleteMock(){
      let deleteState = await FETCH_MOCK_LIST({
        type: 'delete',
        id: this.mockId,
        name: this.name
      })
      if(deleteState.ok === 1){
        this.remove_mockList(this.mockId)
        this.callback()
      }
    },
    async fetchCode(){
      let codeState = await FETCH_MOCK_LIST({
        type: 'readCode',
        name: this.name
      })
      this.code = codeState.data
    }
  },
  computed: mapState([
    'apiList',
    'mockList'
  ])
} as ComponentOptions<EditMock>
开发者ID:jfengsky,项目名称:cquick,代码行数:31,代码来源:EditMock.ts

示例8: data

export default {
  template: `<div>
              <ul>
                <li v-for="item in fileMockList">
                  <div>{{item}}</div>
                  <button @click="deleteData(item)">删除</button>
                </li>
              </ul>
            </div>`,
  data(){
    return {
      
    }
  },
  components:{},
  methods:{
    deleteData(data){
      FETCH_MOCK_CHANGE({
        type: 'delete',
        id: data._id
      })
    },
  },
  computed: {
    
    ...mapState([
      'fileMockList'
    ])
  }
} as ComponentOptions<MockList>
开发者ID:jfengsky,项目名称:cquick,代码行数:30,代码来源:MockList.ts

示例9: render

export default Vue.extend({
  name: 'blur-div',
  props: {
    blur: {
      required: true,
      type: Number
    },
    isTopNav: {
      type: Boolean,
      'default': false
    }
  },
  computed: {
    ...mapState({
      background: (state: RootState) => state.meta.themeConfig.background,
      blurTarget: (state: RootState) => state.meta.themeConfig.blur
    })
  },
  render(h) {
    const {
      url, css_size, css_position,
      enable_picture, background_color,
      gradient_color
    } = this.background as ThemeBackground;
    const { blur, isTopNav } = this.$props;
    const { font, background_color: blur_color, hide_overflow, opacity } = this.blurTarget as ThemeBlur;

    const absoluteStyle: any = {
      position: 'absolute',
      top: '0',
      left: '0',
开发者ID:Johnny-jiangli,项目名称:hexo-theme-lite,代码行数:31,代码来源:blur-div.component.ts

示例10: ChangeMock

    EditMock
  },
  methods: {
    ...mapActions([]),
    ChangeMock(ev) {
      this.mockId = ev.target.value
      this.isEdit = false
      FETCH_MOCK_CHANGE({
        type: 'modify',
        pid: this.mockId,
        id: this.id
      })
    },
    clickHandleEdit() {
      this.isEdit = true
    },
    modifyBack() {
      this.isEdit = false
    }
  },
  computed: {
    ...mapState([
      'apiList',
      'mockList',
      'fileMockList'
    ]),
    currentMockList() {
      return this.mockList.filter((item:ITMockListInfo) => item.pid === this.id)
    }
  }
} as ComponentOptions<ApiInfo>
开发者ID:jfengsky,项目名称:cquick,代码行数:31,代码来源:ApiInfo.ts


注:本文中的vuex.mapState函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。