Exclusive tips every week

Join 13,567+ other Vue devs and get exclusive tips and insights delivered straight to your inbox, every week.

    Picture of Michael Thiessen

    πŸ‘‹Hey friend! I work hard to send you amazing stuff each week.

    β€”Β Michael

    I really love and enjoy reading these emails.

    You are one of the most pro VueJS devs I know, and I am happy that you share this knowledge.

    Fabian Beer

    Here's my latest newsletter

    πŸ”₯ (250) Context-Aware Components, Unit Testing in Nuxt, and Mocking Components

    Hey!

    Happy New Year's Eve! It's been an amazing year for Vue and Nuxt. Wishing you all the best for 2026.

    Let's close out the year with some tips and articles.

    β€” Michael

    πŸ”₯ Creating Magic with Context-Aware Components

    Context-aware components are "magical" β€” they adapt to what's going on around them automatically, handling edge cases, state sharing, and more.

    There are 3 main types of context-aware components, but configuration is the one I find most interesting.

    1. State Sharing

    When you break up a large component into smaller ones, they often still need to share state.

    Instead of pushing that work on whoever's consuming the components, you can make this happen "behind the scenes."

    To give you more flexibility, you may break up a Dropdown component into Select and Option components. But to make it easier to use, the Select and Option components share the selected state with each other:

    <!-- Used as a single component for simplicity -->
    <Dropdown v-model="selected" :options="[]" />
    <!-- Split up for more flexibility -->
    <Select v-model="selected">
    <Option value="mustard">Mustard</Option>
    <Option value="ketchup">Ketchup</Option>
    <div class="relish-wrapper">
    <Option value="relish">Relish</Option>
    </div>
    </Select>

    2. Configuration

    Sometimes component behaviour needs to change based on what's going on in the rest of the application. This is often done to automagically handle edge cases that would otherwise be annoying to deal with.

    A Popup or Tooltip should reposition itself so it doesn't overflow out of the page. But if that component is inside a modal, it should move, so it doesn't overflow out of the modal.

    This can be done automagically if the Tooltip knows when it's inside a modal.

    3. Styling

    You already create context-aware CSS, applying different styles based on what's happening in parent or sibling elements.

    .statistic {
    color: black;
    font-size: 24px;
    font-weight: bold;
    }
    /* Give some separation between stats
    that are right beside each other */
    .statistic + .statistic {
    margin-left: 10px;
    }

    CSS variables let us push this further, allowing us to set different values in different parts of the page.

    πŸ”₯ Easy Unit Testing in Nuxt

    For your unit tests, @nuxt/test-utils lets you opt-in to a Nuxt environment by adding .nuxt. to the filename of your test:

    ./tests/MyComponent.nuxt.test.ts

    You can also add a special comment at the top of the file:

    @vitest-environment nuxt

    Or enable the environment for all Vitest tests in your config:

    // vitest.config.ts
    import { defineVitestConfig } from '@nuxt/test-utils/config';
    export default defineVitestConfig({
    test: {
    environment: 'nuxt'
    },
    };

    πŸ”₯ Mock Nuxt Components When Testing

    When testing, you'll often need to shallow render a componentΒ β€” mocking out any descendent components to keep your test simpler.

    With @nuxt/test-utils you can use the mockComponent utility method to help with that:

    import { mockComponent } from '@nuxt/test-utils/runtime';
    // Use Options API to configure
    mockComponent('MyComponent', {
    props: {
    value: String
    },
    setup(props) {
    // ...
    },
    });
    // Or use a separate file to clean things up (and use <script setup>)
    mockComponent('MyComponent', () => import('./MyComponent.mock.vue'));
    // ...tests

    πŸ“œ Adding Drag and Drop (video)

    In this video from LearnVue, we see how easy it can be to add a powerful drag and drop system in to your app.

    Check it out here: Adding Drag and Drop (video)

    πŸ“œ Bulletproof Watchers in Vue

    Learn how to write bulletproof watchers in Vue, when to use onCleanup and onWatcherCleanup, and how to build reusable cleanup helpers.

    Check it out here: Bulletproof Watchers in Vue

    πŸ’¬ Chaos

    "Automating chaos just gives faster chaos." β€”Β Mark Fewster

    🧠 Spaced-repetition: From Options to Composition β€” The Easy Way

    The best way to commit something to long-term memory is to periodically review it, gradually increasing the time between reviews πŸ‘¨β€πŸ”¬

    Actually remembering these tips is much more useful than just a quick distraction, so here's a tip from a couple weeks ago to jog your memory.

    You can use reactive to make the switch from the Options API a little easier:

    // Options API
    export default {
    data() {
    username: 'Michael',
    access: 'superuser',
    favouriteColour: 'blue',
    },
    methods: {
    updateUsername(username) {
    this.username = username;
    },
    }
    };

    We can get this working using the Composition API by copying and pasting everything over using reactive:

    // Composition API
    setup() {
    // Copy from data()
    const state = reactive({
    username: 'Michael',
    access: 'superuser',
    favouriteColour: 'blue',
    });
    // Copy from methods
    updateUsername(username) {
    state.username = username;
    }
    // Use toRefs so we can access values directly
    return {
    updateUsername,
    ...toRefs(state),
    }
    }

    We also need to make sure we change this β†’ state when accessing reactive values, and remove it entirely if we need to access updateUsername.

    Now that it’s working, it’s much easier to continue refactoring using ref if you want to β€” or just stick with reactive.

    Michael Hoffman curates a fantastic weekly newsletter with the best Vue and Nuxt links.

    Sign up for it here.

    p.s. I also have a bunch of products/courses:

    Here's what others are saying

    I'm starting to think that your newsletter is one of the best things that happened to me this year. I just love these emails.
    Stanislaw Gregor
    I'm somewhere in the upper-middle level at Vue, and I never miss an email you and always find something cool when reading!
    Eduard Climov
    This is the first time where I'm actually enjoying email newsletters. I like your format a lot.
    Fahmi Alfituri
    You have great content in your emails. I seriously learn something from every one of them.
    Titus Decali
    Just wanted to say I enjoy these emails. They encourage me to constantly improve my craft. Fantastic work.
    Joe Radman
    Thanks for another beautiful tip πŸ™
    Victor Martins Onuoha
    Loving these, and the spaced repetition.
    Mark Goldstein
    I really enjoy reading your emails, because I love Vue. Thanks for these emails.
    Arturo Espinoza
    I really love and enjoy reading these emails. You are one of the most pro VueJS devs I know, and I am happy that you share this knowledge.
    Fabian Beer
    THANK YOU! I did not know about the deep property, so I assumed you simply couldn't watch objects.
    Darryl Noakes
    I really must say you are doing a really great job. Now I am aware of a cleaner and more performant way to use Tailwind. Thanks a lot!
    Henry Eze
    Thank you so much, I really enjoy and appreciate your emails.
    Carlos Gonzalez
    Thanks for sharing great Vue tips.
    Fernando Navarro
    I really enjoy these tips.
    Martin H
    Thank you so much for the weekly Vue education. Thanks and live on longer to educate us more.
    Kabolobari Benakole
    I look forward to your emails every week. This week was something I knew, but I like to be reminded of. Thanks for keeping it up!
    Nathan Strutz
    Thank you for your weekly emails. I always look forward to learning a new tip about Vue or at least relearning old tips :)
    Colin Johnson
    I have really been enjoying your weekly emails, and I also got my two team members to join in on the fun as well.
    Keith Dawson
    Thank you for your newsletter, your explanations have very concise examples and I like it.
    Nicolas Decayeux
    Thanks A LOT for your great work!!! One of the few newsletters that I let pass!
    Martin Tillmann

    Want to level up your Vue skills?

    With over two million reads and 11,067 subscribers, you've come to the right place.

    Subscribe now to get exclusive insights and tips every week.