Code Monkey home page Code Monkey logo

Comments (3)

unclay avatar unclay commented on July 30, 2024

vue-router里配置titlestylewebview(站内app右上角简易配置)

// router config
const getMeta = (to) => {
  return Object.assign({}, to.meta, to.matched[0].meta);
}
router.beforeEach((to, form, next) => {
  const toMeta = getMeta(to);
  // title
  if (toMeta.title) document.title = toMeta.title;
  // style
  if (toMeta.style) {
    for (const i in toMeta.style) {
      document.body.style[i] = toMeta.style[i];
    }
  }
  // webview
  if (toMeta.webview) {
    bzShare.share({
      app: {
        bzWebviewBtn: toMeta.webview,
      },
    });
  }
  return next();
});
// page route
export default {
  path: '/test',
  name: 'test',
  component: testComponent,
  meta: {
    title: 'test title',
    style: {
      backgroundColor: '#efeff4',
    },
    webview: '1100',
  },
}

from blog.

unclay avatar unclay commented on July 30, 2024

App登录处理

const debug = localStorage.getItem('project_debug');
router.beforeEach((to, form, next) => {
  // 是否需要登录
  if (!to.meta.login) {
    return next();
  }
  // 已有登录信息
  if (store.state.user) {
    return next();
  }
  // 兼容开发模式
  const afterLogin = (callback) => {
    if (debug) {
      console.debug('[debug] 跳过登录逻辑');
      callback && callback();
    } else {
      bzLogin.afterAllLogin(callback);
    }
  }
  afterLogin(() => {
    store.dispatch('getUser', {
      success() {
        next();
      },
      error(err) {
        console.log(err);
      }
    });
  });
});

from blog.

unclay avatar unclay commented on July 30, 2024

路由百度统计pv、uv处理
必须指定 location.pathname 路径,站内大部分地址代理过,如果不加会统计到M站首页根目录下面去

router.afterEach((to, from, next) => {
  if (window._hmt && to.path) {
    const location = window.location
    const pagePath = location.pathname + '#' + to.fullPath
    window._hmt.push(['_trackPageview', pagePath])
  }
});

from blog.

Related Issues (1)

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.