Coder Social home page Coder Social logo

vok123 / vue3-ts-vite-ssr-starter Goto Github PK

View Code? Open in Web Editor NEW
162.0 9.0 50.0 601 KB

Use vue3 vite4 typescript eslint SSR pinia unocss vue-router element-plus scss

License: MIT License

JavaScript 47.00% HTML 2.45% Vue 18.30% CSS 1.28% TypeScript 29.97% SCSS 1.00%
ssr vue vite typescript pinia

vue3-ts-vite-ssr-starter's Introduction

vue3-ts-vite-ssr-starter

  • Lightning-fast cold server start
  • Instant hot module replacement (HMR) and dev SSR
  • True on-demand compilation
  • Use vue3 vite4.0 typescript eslint SSR pinia unocss vue-router element-plus scss

Getting Started

  • dev
npm i
npm run dev
  • preview
npm i
npm run preview
  • build
npm i
npm run build

vue3-ts-vite-ssr-starter's People

Contributors

vok123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue3-ts-vite-ssr-starter's Issues

vue-extend.d.ts

vue-extend.d.ts error

import { IRootStore } from '../store'

.vue is not ssr

<template>
  <div class="index">
    <ElSwitch v-model="isActive" active-color="#13ce66" inactive-color="#ff4949">
      switch
    </ElSwitch>
    <div v-for="item in fruitList" :key="item.id">{{ item.name }}</div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, toRefs, onMounted } from 'vue';
import { ElSwitch } from 'element-plus';
import 'element-plus/theme-chalk/el-switch.css';
import { useMarket } from '@/store/market';

export default defineComponent({
  name: 'Index',
  components: {
    ElSwitch
  },
  setup () {
    const state: any = reactive({
      fruitList: []
    });
    const isActive = ref(false);

    // const marketStore = useMarket();
    // await marketStore.getList();
    // const { fruitList } = marketStore;
    // state.fruitList = fruitList;

    const getData = async () => {
      const marketStore = useMarket();
      await marketStore.getList();
      const { fruitList } = marketStore;
      state.fruitList = fruitList;
    };

    onMounted(() => {
      getData(); // not ssr
    });

    return {
      ...toRefs(state),
      isActive
    };
  }
});
</script>

<style scoped>

</style>

remove getData methods is ok.

Cannot run "npm run dev"

Thank you for your wonderfull repo, I got stuck when I run "npm run dev"
I got these error:
image
Is it because vite or the config ? Btw, I'm new in vite.
Thanks before!

some troubles

  1. Not provide (entry-server.js):
app.provide(ID_INJECTION_KEY, {
    prefix: 1024,
    current: 0
  });

When run yarn dev, on pages: User, Market occur warning in console:

ElementPlusError: [IdInjection] Looks like you are using server rendering, you must provide a id provider to ensure the hydration process to be succeed
usage: app.provide(ID_INJECTION_KEY, {
  prefix: number,
  current: number,
})
  1. When run the App in SPA mode (vite --force):
    On pages User, Market occur errors:

Снимок экрана 2023-04-26 в 23 07 16

  1. yarn.lock file is corrupt
  2. pnpm-lock.yaml is old version.

JSX/TSX example request

Hello,

How to use asyncData({ store }) inside vue3 composition API setup() method?

I use JSX/TSX which is a return result of setup() method:

import { defineComponent, computed, ref } from "vue";
import { useRoute } from "vue-router";
import { useStore } from "vuex";
import { IRootState } from "@/store"

export default defineComponent({
    name: 'SomeComponent',

    setup() {
        const route = useRoute()
        const times = ref(0)

        // use computed
        const doubleTimes = computed(() => { return times.value * 2 })

        // asyncData({ store }) {
        //     console.log('!!!!!!!!!!!!!! asyncData !!!!!!!!!!!!!!!!!!!!');
        //     return store.dispatch('market/getFruitList');
        // },

        return () => (
            <div>
                <h2> +1S !!! </h2>
                <button onClick={() => { times.value++ }}>Times+1</button>
                <div>{times.value}</div>
                <div>{doubleTimes.value}</div>
                <div>{route.params.domain}</div>

                <div>{JSON.stringify(fruitList.value, null, 2)}</div>

            </div>
        )
    }
})

What I need is to access fruitList from inside JSX/TSX markup. Maybe some kind of life-cycle hook like https://v3.vuejs.org/api/composition-api.html#lifecycle-hooks
Can you please suggest how to do it?

组件样式没有ssr

/user 页面并刷新,页面会闪动(是动态渲染的),组件的样式有问题

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.